Add a privilege checker in stt_set_engine() 11/127711/1 accepted/tizen/unified/20170429.024458 submit/tizen/20170428.104155
authorsooyeon.kim <sooyeon.kim@samsung.com>
Wed, 25 Jan 2017 12:26:43 +0000 (21:26 +0900)
committerSooyeon Kim <sooyeon.kim@samsung.com>
Fri, 28 Apr 2017 10:31:23 +0000 (10:31 +0000)
Change-Id: Ieb78639f21e92bf89d3c2f04684ae05d915ac092
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 6f65c05084817b30106fc8fe721c3cd2a400e7a0)

client/stt.c
common/stt_defs.h

index b082568..6dfe4ea 100644 (file)
@@ -43,6 +43,8 @@ static float g_volume_db = 0;
 static int g_feature_enabled = -1;
 
 static int g_privilege_allowed = -1;
+static int g_privilege_applaunch_allowed = -1;
+
 static cynara *p_cynara = NULL;
 
 static bool g_err_callback_status = false;
@@ -91,7 +93,7 @@ static int __check_privilege_initialize()
        return ret == CYNARA_API_SUCCESS;
 }
 
-static int __check_privilege(const char* uid, const char * privilege)
+static bool __check_privilege(const char* uid, const char * privilege)
 {
        FILE *fp = NULL;
        char label_path[1024] = "/proc/self/attr/current";
@@ -143,7 +145,7 @@ static int __stt_check_privilege()
                        return STT_ERROR_PERMISSION_DENIED;
                }
                snprintf(uid, 16, "%d", getuid());
-               if (false == __check_privilege(uid, STT_PRIVILEGE)) {
+               if (false == __check_privilege(uid, STT_PRIVILEGE_RECORDER)) {
                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied");
                        g_privilege_allowed = 0;
                        __check_privilege_deinitialize();
@@ -156,6 +158,32 @@ static int __stt_check_privilege()
        return STT_ERROR_NONE;
 }
 
+static int __stt_check_privilege_for_applaunch()
+{
+       char uid[16];
+
+       if (0 == g_privilege_applaunch_allowed) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission for applaunch is denied");
+               return STT_ERROR_PERMISSION_DENIED;
+       } else if (-1 == g_privilege_applaunch_allowed) {
+               if (false == __check_privilege_initialize()) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)");
+                       return STT_ERROR_PERMISSION_DENIED;
+               }
+               snprintf(uid, 16, "%d", getuid());
+               if (false == __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH)) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch");
+                       g_privilege_applaunch_allowed = 0;
+                       __check_privilege_deinitialize();
+                       return STT_ERROR_PERMISSION_DENIED;
+               }
+               __check_privilege_deinitialize();
+       }
+
+       g_privilege_applaunch_allowed = 1;
+       return STT_ERROR_NONE;
+}
+
 static const char* __stt_get_error_code(stt_error_e err)
 {
        switch (err) {
@@ -621,6 +649,9 @@ int stt_set_engine(stt_h stt, const char* engine_id)
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
+       if (0 != __stt_check_privilege_for_applaunch()) {
+               return STT_ERROR_PERMISSION_DENIED;
+       }
        if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
@@ -877,6 +908,7 @@ int stt_set_server_stt(stt_h stt, const char* key, char* user_data)
 static Eina_Bool __stt_connect_daemon(void *data)
 {
        stt_client_s* client = (stt_client_s*)data;
+       int ret = -1;
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
@@ -884,8 +916,17 @@ static Eina_Bool __stt_connect_daemon(void *data)
                return EINA_FALSE;
        }
 
+       /* Check and Set vconfkey of custom engine before sending hello */
+       if (1 == g_privilege_applaunch_allowed && NULL != client->current_engine_id) {
+               /* Set vconfkey */
+               ret = __stt_set_buxtonkey(client->current_engine_id);
+               if (0 != ret) {
+                       SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] set buxtonkey Failed!!! (inside __stt_connect_daemon)");
+                       return EINA_TRUE;
+               }
+       }
+
        /* Send hello */
-       int ret = -1;
        ret = stt_dbus_request_hello(client->uid);
 
        if (0 != ret) {
index 00f8522..465e22c 100644 (file)
@@ -102,7 +102,8 @@ extern "C" {
 #define STT_FEATURE_PATH               "tizen.org/feature/speech.recognition"
 #define STT_MIC_FEATURE_PATH           "tizen.org/feature/microphone"
 
-#define STT_PRIVILEGE                  "http://tizen.org/privilege/recorder"
+#define STT_PRIVILEGE_RECORDER                 "http://tizen.org/privilege/recorder"
+#define STT_PRIVILEGE_APPLAUNCH                        "http://tizen.org/privilege/appmanager.launch"
 
 #ifdef __cplusplus
 }