Fix download-fonts-service package for Tizen 3.0
[platform/core/uifw/download-fonts-service.git] / pkgmgr_font / src / font_service_register.c
index 31e62e7..3147a7d 100755 (executable)
@@ -28,7 +28,7 @@
 #include <fontconfig/fontconfig.h>
 #include <Elementary.h>
 #include <pkgmgr-info.h>
-#include <security-server.h>
+#include <pkgmgr_installer_info.h>
 #include "system_settings.h"
 
 
@@ -49,8 +49,8 @@ static const char *PRELOADED_PATH = "/opt/share/fonts/preloaded";
 
 static const char *ELM_PROFILE_CFG = "/opt/home/app/.elementary/config/profile.cfg";
 #define MAX_FILE_LEN 4096
-#define APP_OWNER_ID 5000
-#define APP_GROUP_ID 5000
+#define APP_OWNER_ID 5001
+#define APP_GROUP_ID 100
 
 static int make_dir(const char *path);
 static int symbolic_link(const char *srcpath, const char *destpath);
@@ -95,7 +95,14 @@ static int make_dir(const char *path)
                        return ret;
                }
 
-               ret = chmod (path, 0755);
+               ret = chown(path, getuid(), APP_GROUP_ID);
+               if (ret < 0)
+               {
+                       DEBUG_ERROR("chown is failed %s\n",path);
+                       return ret;
+               }
+
+               ret = chmod(path, 0755);
                if (ret < 0)
                {
                        DEBUG_ERROR("chmod is failed %s\n",path);
@@ -103,13 +110,6 @@ static int make_dir(const char *path)
                        return ret;
                }
        }
-       ret = security_server_label_access(path, "_");
-
-       if (ret < 0)
-       {
-               DEBUG_ERROR("security_server_label_access is failed %s\n",path);
-               return ret;
-       }
 
        return ret;
 }
@@ -174,14 +174,6 @@ static int symbolic_link(const char *srcpath, const char *destpath)
                                DEBUG_ERROR("symlink is failed \n");
                                goto FAIL;
                        }
-
-                       ret = security_server_label_access(destdir, "_");
-
-                       if (ret < 0)
-                       {
-                               DEBUG_ERROR("security_server_label_access is failed %s\n",destdir);
-                               goto FAIL;
-                       }
                }
        }
        closedir (d);
@@ -247,14 +239,6 @@ static int move_file(const char *srcpath, const char *destpath)
                                DEBUG_ERROR("symlink is failed \n");
                                goto FAIL;
                        }
-
-                       ret = security_server_label_access(destdir, "_");
-
-                       if (ret < 0)
-                       {
-                               DEBUG_ERROR("security_server_label_access is failed %s\n",destdir);
-                               goto FAIL;
-                       }
                }
        }
        closedir (d);
@@ -500,8 +484,11 @@ int COMMON_PKGMGR_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *li
        pkgmgrinfo_pkginfo_h handle = NULL;
        const char *app_root_path = NULL;
        const char *dest_path = NULL;
+       uid_t uid = 0;
+
+       pkgmgr_installer_info_get_target_uid(&uid);
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
 
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
        if (ret < 0)
        {
                DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
@@ -561,8 +548,11 @@ int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *li
        pkgmgrinfo_pkginfo_h handle = NULL;
        const char* app_root_path = NULL;
        const char* dest_path = NULL;
+       uid_t uid = 0;
+
+       pkgmgr_installer_info_get_target_uid(&uid);
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
 
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
        if (ret < 0)
        {
                DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
@@ -594,7 +584,7 @@ int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *li
 
        if (access(deletedir, F_OK) == -1)
        {
-               DEBUG_ERROR("dest directory is not exist \n");
+               DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno));
                goto FAIL;
        }
 
@@ -606,18 +596,16 @@ int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *li
        }
 
        ret = make_dir(PARENT_PATH);
-
        if (ret < 0)
        {
-               DEBUG_ERROR("make current directory is failed \n");
+               DEBUG_ERROR("make current directory(%s) is failed: %s\n", PARENT_PATH, strerror(errno));
                goto FAIL;
        }
 
        ret = make_dir(dest_path);
-
        if (ret < 0)
        {
-               DEBUG_ERROR("make current directory is failed \n");
+               DEBUG_ERROR("make current directory(%s) is failed: %s\n", dest_path, strerror(errno));
                goto FAIL;
        }
 
@@ -644,9 +632,11 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
        FcObjectSet *os = NULL;
        FcPattern *pat = NULL;
        FcFontSet *fs = NULL;
+       pkgmgrinfo_pkginfo_h handle = NULL;
        const char* app_root_path = NULL;
        const char *dest_path = NULL;
        int ret;
+       uid_t uid = 0;
 
        elm_init(0, NULL);
 
@@ -656,10 +646,9 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
                return -1;
        }
 
-       pkgmgrinfo_pkginfo_h handle = NULL;
-
+       pkgmgr_installer_info_get_target_uid(&uid);
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
 
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
        if (ret < 0)
        {
                DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
@@ -753,12 +742,6 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
                                                chmod (ELM_PROFILE_CFG, 0777);
                                        }
 
-                                       ret = security_server_label_access(ELM_PROFILE_CFG, "system::homedir");
-                                       if (ret < 0)
-                                       {
-                                               chmod (ELM_PROFILE_CFG, 0777);
-                                       }
-
                                        DIR *d = NULL;
                                        struct dirent *e;
 
@@ -781,13 +764,6 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
                                                                        DEBUG_LOG("chown is failed %s", file_full_path);
                                                                        chmod (file_full_path, 0777);
                                                                }
-
-                                                               ret = security_server_label_access(file_full_path, "system::homedir");
-                                                               if (ret < 0)
-                                                               {
-                                                                       DEBUG_LOG("chsmack is failed %s", file_full_path);
-                                                                       chmod (file_full_path, 0777);
-                                                               }
                                                        }
                                                }
 
@@ -805,7 +781,7 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *
 
        if (access(deletedir, F_OK) == -1)
        {
-               DEBUG_ERROR("dest directory(%s) is not exist \n", deletedir);
+               DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno));
                goto FAIL;
        }