Use pkgmgrinfo_pkginfo_get_usr_pkginfo() when getting package info 77/208777/1
authorYunjin Lee <yunjin-.lee@samsung.com>
Fri, 28 Jun 2019 04:06:59 +0000 (13:06 +0900)
committerYunjin Lee <yunjin-.lee@samsung.com>
Fri, 28 Jun 2019 07:04:41 +0000 (16:04 +0900)
Change-Id: Ia3314369c52786f010d48c268a71025872acef08
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
capi/include/privilege_info.h
capi/src/privilege_info.c
capi/src/privilege_package_info.c

index 61092adf03e8c75380c558fee85df8f924f287b1..bc03b5b3e1d5d61243518f4a1a21a45a2b2d5b7c 100644 (file)
@@ -31,7 +31,7 @@ extern "C" {
  * @brief Free GList allocated by privilege_info APIs
  * @param [in] list The GList allocated by privilege_info APIs
  */
-void privilege_info_list_free(GList* list);
+EXPORT_API void privilege_info_list_free(GList* list);
 
 /**
  * @brief Called to get a privilege group once for specific package.
@@ -53,6 +53,21 @@ typedef int (*privilege_info_privilege_groups_cb) (const char *privilege_group,
  */
 typedef int (*privilege_info_privileges_cb) (const char *privilege, void* user_data);
 
+/**
+ * @brief Retrieves privilege group list of the package.
+ * @param [in] package_id The package id
+ * @param [in] uid The uid of the package
+ * @param [in] callback The callback function to invoke
+ * @param [in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a nonzero error value.
+ * @retval #PRVMGR_ERR_NONE Successful
+ * @retval #PRVMGR_ERR_INTERNAL_ERROR Internal error
+ * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter
+ * @post       This function invokes privilege_info_privilege_groups_cb() repeatedly for each application context.
+ * @see privilege_info_privilege_groups_cb()
+ */
+EXPORT_API int privilege_info_foreach_privilege_group_list_by_pkgid_and_uid(const char *package_id, uid_t uid, privilege_info_privilege_groups_cb callback, void* user_data);
+
 /**
  * @brief Retrieves privilege group list of the package.
  * @param [in] package_id The package id
@@ -67,6 +82,21 @@ typedef int (*privilege_info_privileges_cb) (const char *privilege, void* user_d
  */
 EXPORT_API int privilege_info_foreach_privilege_group_list_by_pkgid(const char *package_id, privilege_info_privilege_groups_cb callback, void* user_data);
 
+/**
+ * @brief Retrieves privilege list in specific group of the package.
+ * @param [in] package_id The package id
+ * @param [in] uid The uid of the package
+ * @param [in] callback The callback function to invoke
+ * @param [in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a nonzero error value.
+ * @retval #PRVMGR_ERR_NONE Successful
+ * @retval #PRVMGR_ERR_INTERNAL_ERROR Internal error
+ * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter
+ * @see privilege_info_privileges_cb()
+ */
+EXPORT_API int privilege_info_foreach_privilege_list_by_pkgid_and_privilege_group_and_uid(const char *package_id, uid_t uid, const char* privilege_group, privilege_info_privileges_cb callback, void* user_data);
+
+
 /**
  * @brief Retrieves privilege list in specific group of the package.
  * @param [in] package_id The package id
index 79f9f67ab1b227c492a8dea0dc0d5fb43efb171e..be6417b043ec575e34cde4ce6a2e8a291870d3e9 100755 (executable)
@@ -78,6 +78,33 @@ int privilege_info_privilege_list_by_pkgid_callback(const char *privilege_name,
        return PRVMGR_ERR_NONE;
 }
 
+int privilege_info_foreach_privilege_group_list_by_pkgid_and_uid(const char *package_id, uid_t uid, privilege_info_privilege_groups_cb callback, void *user_data)
+{
+       int groupTable[MAX_PRV_GROUP] = { 0, };
+       int i = 0;
+       int res = PRVMGR_ERR_NONE;
+
+       TryReturn(package_id != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] package_id is NULL");
+       TryReturn(callback != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] callback is NULL");
+
+       pkgmgrinfo_pkginfo_h handle;
+       res = pkgmgrinfo_pkginfo_get_usr_pkginfo(package_id, uid, &handle);
+       TryReturn(res == PMINFO_R_OK, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] pkgmgrinfo_pkginfo_get_usr_pkginfo is failed.");
+
+       res = pkgmgrinfo_pkginfo_foreach_privilege(handle, privilege_info_privilege_list_by_pkgid_callback, &groupTable);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       TryReturn(res == PMINFO_R_OK, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] pkgmgrinfo_pkginfo_foreach_privilege is failed.");
+
+       for (i = 0; i < MAX_PRV_GROUP; i++) {
+               if (groupTable[i] == 1) {
+                       res = callback(privilege_group_info_table[i].privilege_group, user_data);
+                       TryReturn(res >= 0, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] return value of callback function is negative.");
+               }
+       }
+
+       return PRVMGR_ERR_NONE;
+}
+
 int privilege_info_foreach_privilege_group_list_by_pkgid(const char *package_id, privilege_info_privilege_groups_cb callback, void *user_data)
 {
        int groupTable[MAX_PRV_GROUP] = { 0, };
@@ -152,6 +179,39 @@ int privilege_info_privilege_list_callback(const char *privilege_name, void *use
        return PRVMGR_ERR_NONE;
 }
 
+int privilege_info_foreach_privilege_list_by_pkgid_and_privilege_group_and_uid(const char *package_id, uid_t uid, const char *privilege_group, privilege_info_privileges_cb callback, void *user_data)
+{
+       int i = 0;
+       int res = PRVMGR_ERR_NONE;
+       privilege_list_cb_data data;
+
+       TryReturn(package_id != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] package_id is NULL");
+       TryReturn(privilege_group != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] privilege_group is NULL");
+       TryReturn(callback != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] callback is NULL");
+
+       data.privilege_group = -1;
+       data.callback = callback;
+       data.user_data = user_data;
+
+       for (i = 0; i < MAX_PRV_GROUP; i++) {
+               if (strcmp(privilege_group_info_table[i].privilege_group, privilege_group) == 0) {
+                       data.privilege_group = privilege_group_info_table[i].privilege_group_enum;
+                       break;
+               }
+       }
+
+       if (data.privilege_group > -1) {
+               pkgmgrinfo_pkginfo_h handle;
+               res = pkgmgrinfo_pkginfo_get_usr_pkginfo(package_id, uid, &handle);
+               TryReturn(res == PMINFO_R_OK, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] pkgmgrinfo_pkginfo_get_usr_pkginfo is failed.");
+               res = pkgmgrinfo_pkginfo_foreach_privilege(handle, privilege_info_privilege_list_callback, &data);
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+               TryReturn(res == PMINFO_R_OK, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] pkgmgrinfo_pkginfo_foreach_privilege is failed.");
+       }
+
+       return PRVMGR_ERR_NONE;
+}
+
 int privilege_info_foreach_privilege_list_by_pkgid_and_privilege_group(const char *package_id, const char *privilege_group, privilege_info_privileges_cb callback, void *user_data)
 {
        int i = 0;
@@ -503,14 +563,14 @@ int privilege_info_is_privacy(const char* privilege)
        return ret;
 }
 
-static int __get_pkg_type(const char *pkgid, privilege_manager_package_type_e *pkg_type)
+static int __get_pkg_type(uid_t uid, const char *pkgid, privilege_manager_package_type_e *pkg_type)
 {
        int ret = 0;
        char *type = NULL;
        pkgmgrinfo_pkginfo_h handle;
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
        if (ret != PMINFO_R_OK) {
-               LOGE("failed to get pkginfo handle! pkgid <%s>", pkgid);
+               LOGE("failed to get pkginfo handle! pkgid <%s> uid <%d>", pkgid, uid);
                return -1;
        }
        ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
@@ -540,7 +600,7 @@ int privilege_info_get_privilege_type(uid_t uid, const char* pkgid, const char*
                        ret = PRVMGR_ERR_NONE;
                } else if (ret == 0) {
                        privilege_manager_package_type_e pkg_type = PRVMGR_PACKAGE_TYPE_NONE;
-                       ret = __get_pkg_type(pkgid, &pkg_type);
+                       ret = __get_pkg_type(uid, pkgid, &pkg_type);
                        TryReturn(ret == 0 && pkg_type != PRVMGR_PACKAGE_TYPE_NONE, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] failed to get pkg type of <%s>", pkgid);
 
                        bool is_requestable = false;
index 77c095108fa1bc0231cbeaaedffef32947bca41f..4223836531aa12266d8d67efcc078248aadc518c 100755 (executable)
@@ -74,12 +74,12 @@ int privilege_package_info_unset_package_privilege_info(const uid_t uid, const c
        return PRVMGR_ERR_NONE;
 }
 
-static int __get_pkg_type(const char *pkgid, privilege_manager_package_type_e *pkg_type)
+static int __get_pkg_type(uid_t uid, const char *pkgid, privilege_manager_package_type_e *pkg_type)
 {
        int ret = 0;
        char *type = NULL;
        pkgmgrinfo_pkginfo_h handle;
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
        if (ret != PMINFO_R_OK) {
                LOGE("failed to get pkginfo handle! pkgid <%s>", pkgid);
                return -1;
@@ -103,7 +103,7 @@ int privilege_package_info_is_privacy_requestable(const uid_t uid, const char* p
        TryReturn(pkgid != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] pkgid must not be NULL.");
 
        privilege_manager_package_type_e pkg_type = PRVMGR_PACKAGE_TYPE_NONE;
-       int ret = __get_pkg_type(pkgid, &pkg_type);
+       int ret = __get_pkg_type(uid, pkgid, &pkg_type);
        TryReturn(ret == 0 && pkg_type != PRVMGR_PACKAGE_TYPE_NONE, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] failed to get pkg type of <%s>", pkgid);
        ret = privilege_db_manager_is_privacy_requestable(uid, pkgid, privilege, pkg_type, is_requestable);