Merge "Add metadata for setting app" into tizen
[platform/core/uifw/tts.git] / engine-parser / src / tts-engine-parser.c
index 6e73cbd..68786dc 100644 (file)
@@ -74,7 +74,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;
 
@@ -95,7 +96,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;
@@ -109,6 +110,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);
 
@@ -118,6 +121,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)
@@ -128,6 +133,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) {
@@ -169,6 +176,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");
+                       }
                }
        }
 
@@ -186,6 +198,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");
+                       }
                }
        }
 
@@ -203,6 +220,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");
+                       }
                }
        }
 
@@ -220,6 +242,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");
+                       }
                }
        }
 
@@ -228,6 +255,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;
@@ -414,6 +448,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));
        }
@@ -481,7 +516,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);
@@ -499,6 +534,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);
@@ -531,6 +567,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));
@@ -543,7 +580,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));
@@ -580,7 +617,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");
                                }
 
@@ -675,7 +712,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) {