Fix owner and group in engine-parser 21/109821/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Wed, 28 Dec 2016 07:41:16 +0000 (16:41 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Thu, 12 Jan 2017 02:03:02 +0000 (18:03 -0800)
Change-Id: I09345c445f414cb5a110deb183ad2f64f7e31e92
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 70abf88654689a18dfb17db844b51968f2fd04bd)

engine-parser/src/tts-engine-parser.c

index 2016f5e..53c3e41 100644 (file)
@@ -73,7 +73,8 @@ typedef struct metadata {
 
 static xmlDocPtr g_doc;
 GumUser *g_guser = NULL;
-uid_t g_uid = 5001;
+uid_t g_uid = 301;     // app_fw
+gid_t g_gid = 301;     // app_fw
 GumUserType g_ut = GUM_USERTYPE_NONE;
 gchar *g_user_type = NULL;
 
@@ -94,7 +95,7 @@ static int __create_engine_info_xml(const char *pkgid)
        return 0;
 }
 
-static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
+static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t gid)
 {
        LOGD("=== Save engine info doc");
        char *dir_config_base = NULL;
@@ -108,6 +109,8 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
        }
 
        uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+       uid_t tmp_uid = 0;
+       gid_t tmp_gid = 0;
 
        LOGD("uid(%d)", uid);
 
@@ -117,6 +120,8 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                dir_home = strdup(TTS_GLOBAL_HOME);
                dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
                dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
+               tmp_uid = 301;  // app_fw
+               tmp_gid = 301;  // app_fw
        } else {
                /* User app, Guest app, Security app */
                if (NULL != g_dir_config_base)
@@ -127,6 +132,8 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                        dir_engine_base = strdup(g_dir_engine_base);
                if (NULL != g_dir_engine_info)
                        dir_engine_info = strdup(g_dir_engine_info);
+               tmp_uid = uid;
+               tmp_gid = gid;
        }
 
        if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
@@ -168,6 +175,11 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_config_base);
+                       if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
+                               LOGD("[ERROR] Fail to change user and group");
+                       } else {
+                               LOGD("[DEBUG] Success to change user and group");
+                       }
                }
        }
 
@@ -185,6 +197,11 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_home);
+                       if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
+                               LOGD("[ERROR] Fail to change user and group");
+                       } else {
+                               LOGD("[DEBUG] Success to change user and group");
+                       }
                }
        }
 
@@ -202,6 +219,11 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_engine_base);
+                       if (0 != chown(dir_engine_base, tmp_uid, tmp_gid)) {
+                               LOGD("[ERROR] Fail to change user and group");
+                       } else {
+                               LOGD("[DEBUG] Success to change user and group");
+                       }
                }
        }
 
@@ -219,6 +241,11 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_engine_info);
+                       if (0 != chown(dir_engine_info, tmp_uid, tmp_gid)) {
+                               LOGD("[ERROR] Fail to change user and group");
+                       } else {
+                               LOGD("[DEBUG] Success to change user and group");
+                       }
                }
        }
 
@@ -227,6 +254,13 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
        snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
        int ret = xmlSaveFormatFile(path, g_doc, 1);
        LOGD("xmlSaveFile (%d)", ret);
+       if (0 == ret) {
+               if (0 != chown(path, tmp_uid, tmp_gid)) {
+                       LOGD("[ERROR] Fail to change user and group");
+               } else {
+                       LOGD("[DEBUG] Success to change user and group");
+               }
+       }
 
        free(dir_config_base);
        dir_config_base = NULL;
@@ -405,6 +439,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        return -1;
                }
 
+               g_object_get(G_OBJECT(g_guser), "gid", &g_gid, NULL);
                g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
                g_user_type = g_strdup(gum_user_type_to_string(g_ut));
        }
@@ -472,7 +507,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        return -1;
                }
 
-               if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid)) {
+               if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
                        LOGE("[ERROR] Fail to make engine info file");
                        xmlFreeDoc(g_doc);
                        g_free(g_user_type);
@@ -490,6 +525,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                gchar *user_type = NULL;
 
                uid_t uid;
+               gid_t gid;
                gchar *home_dir = NULL;
 
                gus = gum_user_service_create_sync(TRUE);
@@ -522,6 +558,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                                free(home_dir);
                                home_dir = NULL;
                        }
+                       g_object_get(G_OBJECT(user), "gid", &gid, NULL);
                        g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
                        g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
                        user_type = g_strdup(gum_user_type_to_string(gumut));
@@ -534,7 +571,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
                        LOGD("[DEBUG] user info");
                        if (NULL != home_dir) {
-                               LOGD("[DEBUG] uid(%d), user_type(%s), home_dir(%s)", uid, user_type, home_dir);
+                               LOGD("[DEBUG] uid(%d), gid(%d),  user_type(%s), home_dir(%s)", uid, gid, user_type, home_dir);
 
                                g_dir_config_base = (char*)calloc(strlen(home_dir) + 14, sizeof(char));
                                g_dir_home = (char*)calloc(strlen(home_dir) + 18, sizeof(char));
@@ -571,7 +608,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
                                LOGD("[DEBUG] g_dir_engine_info(%s)", g_dir_engine_info);
 
-                               if (0 != __save_engine_info_xml(pkgid, user_type, uid)) {
+                               if (0 != __save_engine_info_xml(pkgid, user_type, uid, gid)) {
                                        LOGE("[ERROR] Fail to make engine info file");
                                }
 
@@ -666,7 +703,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        return -1;
                }
 
-               if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid)) {
+               if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
                        LOGE("[ERROR] Fail to make engine info file");
                        xmlFreeDoc(g_doc);
                        if (NULL != g_guser) {