Add uid check routine at cleardata functions
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 19 Dec 2016 05:22:47 +0000 (14:22 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Fri, 23 Dec 2016 08:16:52 +0000 (17:16 +0900)
- Calling cleardata with global uid will not be allowed
  because cleardata will only works for userdata of each user, not pkg itself

Change-Id: I1d1ff1e24f593c080060f16580a40ace17f845f7
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
client/include/package-manager.h
client/src/pkgmgr.c

index d744200..7a93e55 100644 (file)
@@ -550,6 +550,7 @@ int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc, const char *app
  *
  * This API is for package-manager client application.\n
  *
+ * @remarks    You should call this function with regular uid
  * @param[in]  pc      pkgmgr_client
  * @param[in]  pkg_type                package type
  * @param[in]  pkgid   package id
@@ -750,6 +751,7 @@ int pkgmgr_client_usr_request_size_info(uid_t uid);
  *
  * This API is for package-manager client application.\n
  *
+ * @remarks    You should call this function with regular uid
  * @param[in]  pkgid                   package id
  * @return     0 if success, error code(<0) if fail\n
  * @retval     PKGMGR_R_OK     success
@@ -765,6 +767,7 @@ int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid);
  *
  * This API is for package-manager client application.\n
  *
+ * @remarks    You should call this function with regular uid
  * @return     0 if success, error code(<0) if fail\n
  * @retval     PKGMGR_R_OK     success
  * @retval     PKGMGR_R_EINVAL invalid argument
index 76acb22..c594e1f 100644 (file)
@@ -1197,7 +1197,7 @@ API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
        int ret;
        struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
 
-       if (pc == NULL || appid == NULL) {
+       if (pc == NULL || appid == NULL || uid == GLOBAL_USER) {
                ERR("invalid parameter");
                return PKGMGR_R_EINVAL;
        }
@@ -1209,7 +1209,7 @@ API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc,
 
        ret = pkgmgr_client_connection_send_request(client, "cleardata",
                        g_variant_new("(us)", uid, appid), &result);
-       if (ret == PKGMGR_R_OK) {
+       if (ret != PKGMGR_R_OK) {
                ERR("request failed: %d", ret);
                return ret;
        }
@@ -1433,7 +1433,7 @@ API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid)
        int ret;
        struct pkgmgr_client_t *client;
 
-       if (pkgid == NULL) {
+       if (pkgid == NULL || uid == GLOBAL_USER) {
                ERR("invalid parameter");
                return PKGMGR_R_EINVAL;
        }
@@ -1470,7 +1470,7 @@ API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid)
 API int pkgmgr_client_clear_all_cache_dir(void)
 {
        return pkgmgr_client_usr_clear_cache_dir(
-                       PKG_CLEAR_ALL_CACHE, getuid());
+                       PKG_CLEAR_ALL_CACHE, _getuid());
 }
 
 API int pkgmgr_client_get_size(pkgmgr_client *pc, const char *pkgid,