From: Yunjin Lee Date: Thu, 20 Feb 2020 07:43:04 +0000 (+0900) Subject: Remove disabled pakcages from privacy package list X-Git-Tag: submit/tizen/20200221.023300~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F225493%2F1;p=platform%2Fcore%2Fsecurity%2Fprivilege-checker.git Remove disabled pakcages from privacy package list - Modify package list returned by following APIs not to include disabled packages. - privilege_package_info_get_package_list_by_privacy() - privilege_package_info_get_all_privacy_package_list() Change-Id: Ib1de0d07d0c3b395dec05bbfbf9774506e94f8a9 Signed-off-by: Yunjin Lee --- diff --git a/capi/src/privilege_package_info.c b/capi/src/privilege_package_info.c index 4223836..a404901 100755 --- a/capi/src/privilege_package_info.c +++ b/capi/src/privilege_package_info.c @@ -78,7 +78,7 @@ static int __get_pkg_type(uid_t uid, const char *pkgid, privilege_manager_packag { int ret = 0; char *type = NULL; - pkgmgrinfo_pkginfo_h handle; + pkgmgrinfo_pkginfo_h handle = NULL; ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); if (ret != PMINFO_R_OK) { LOGE("failed to get pkginfo handle! pkgid <%s>", pkgid); @@ -98,6 +98,21 @@ static int __get_pkg_type(uid_t uid, const char *pkgid, privilege_manager_packag return 0; } +static bool __is_disabled_package(uid_t uid, const char *pkgid) +{ + pkgmgrinfo_pkginfo_h handle = NULL; + int ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, uid, &handle); + + if (handle != NULL) + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + + if (ret == PMINFO_R_OK) { + return true; + } else { + return false; + } +} + int privilege_package_info_is_privacy_requestable(const uid_t uid, const char* pkgid, const char* privilege, bool* is_requestable) { TryReturn(pkgid != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] pkgid must not be NULL."); @@ -136,6 +151,17 @@ int privilege_package_info_get_all_privacy_package_list(const uid_t uid, GList** LOGE("privilege_db_manager_get_all_privacy_package_list failed. ret = %d", ret); return PRVMGR_ERR_INTERNAL_ERROR; } + + GList *l = NULL; + for(l = *privacy_list; l != NULL;) { // Remove disabled packages + GList *ll = l->next; + if (__is_disabled_package(uid, (const char*)l->data)) { + LOGD("uid = %d, pkgid = %s is disabled package. Remove.", uid, (char*)l->data); + *privacy_list = g_list_remove(*privacy_list, l->data); + } + l = ll; + } + return PRVMGR_ERR_NONE; } @@ -149,6 +175,7 @@ int privilege_package_info_get_privacy_list_by_pkgid(const uid_t uid, const char } return PRVMGR_ERR_NONE; } + int privilege_package_info_get_package_list_by_privacy(const uid_t uid, const char* privacy, GList** package_list) { TryReturn(privacy != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] privacy must not be null"); @@ -157,8 +184,19 @@ int privilege_package_info_get_package_list_by_privacy(const uid_t uid, const ch LOGE("privilege_db_manager_get_package_list_by_privacy failed. ret = %d", ret); return PRVMGR_ERR_INTERNAL_ERROR; } + + GList *l = NULL; + for(l = *package_list; l != NULL;) { // Remove disabled packages + GList *ll = l->next; + if (__is_disabled_package(uid, (const char*)l->data)) { + LOGD("uid = %d, pkgid = %s is disabled package. Remove.", uid, (char*)l->data); + *package_list = g_list_remove(*package_list, l->data); + } + l = ll; + } return PRVMGR_ERR_NONE; } + int privilege_package_info_get_privilege_list_by_pkgid_and_privacy(const uid_t uid, const char* pkgid, const char* privacy, GList** privilege_list) { TryReturn(pkgid != NULL && privacy != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] pkgid and privacy must not be null");