Fix permission denied problem 11/198211/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Mon, 14 Jan 2019 02:20:47 +0000 (11:20 +0900)
committerSooyeon Kim <sooyeon.kim@samsung.com>
Tue, 22 Jan 2019 09:39:08 +0000 (09:39 +0000)
Change-Id: I4fe323760223b8ca57e0ebe90294ea6d02f49a20
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 4097d80069c56bdfff59985f97c3e5f0258892f3)

client/vc_mgr.c
client/vc_mgr_dbus.c

index 00c2e2414ff39c8ea264c650eef67dff457346a2..1d0974fffc395c6a7ee6a60e121efe94522ef524 100644 (file)
@@ -19,6 +19,7 @@
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <cynara-session.h>
+#include <pthread.h>
 
 #include "vc_cmd_db.h"
 #include "vc_config_mgr.h"
@@ -60,6 +61,7 @@ static int g_feature_enabled = -1;
 
 static int g_privilege_allowed = -1;
 static cynara *p_cynara = NULL;
+static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static bool g_err_callback_status = false;
 
@@ -141,20 +143,31 @@ static int __vc_mgr_get_feature_enabled()
 
 static int __check_privilege_initialize()
 {
+       pthread_mutex_lock(&g_cynara_mutex);
+
        int ret = cynara_initialize(&p_cynara, NULL);
-       if (CYNARA_API_SUCCESS != ret)
-               SLOG(LOG_ERROR, TAG_VCM, "[ERROR] fail to initialize");
+       if (NULL == p_cynara || CYNARA_API_SUCCESS != ret) {
+               SLOG(LOG_ERROR, TAG_VCM, "[ERROR] fail to initialize(%d)", ret);
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return ret;
+       }
+
+       SLOG(LOG_ERROR, TAG_VCM, "[DEBUG] success to initialize cynara");
+       pthread_mutex_unlock(&g_cynara_mutex);
 
        return ret == CYNARA_API_SUCCESS;
 }
 
 static int __check_privilege(const char* uid, const char * privilege)
 {
+       pthread_mutex_lock(&g_cynara_mutex);
        FILE *fp = NULL;
        char label_path[1024] = "/proc/self/attr/current";
        char smack_label[1024] = {'\0',};
 
        if (!p_cynara) {
+               SLOG(LOG_ERROR, TAG_VCM, "[ERROR] p_cynara is NULL");
+               pthread_mutex_unlock(&g_cynara_mutex);
                return false;
        }
 
@@ -169,21 +182,28 @@ static int __check_privilege(const char* uid, const char * privilege)
        pid_t pid = getpid();
        char *session = cynara_session_from_pid(pid);
        int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
-       SLOG(LOG_DEBUG, TAG_VCM, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
+       SLOG(LOG_DEBUG, TAG_VCM, "[Client]cynara_check returned %d(%s), p_cynara(%p), label(%s), session(%s), uid(%s), priv(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied", p_cynara, smack_label, session, uid, privilege);
        if (session)
                free(session);
 
-       if (ret != CYNARA_API_ACCESS_ALLOWED)
+       if (ret != CYNARA_API_ACCESS_ALLOWED) {
+               pthread_mutex_unlock(&g_cynara_mutex);
                return false;
+       }
 
+       pthread_mutex_unlock(&g_cynara_mutex);
        return true;
 }
 
 static void __check_privilege_deinitialize()
 {
-       if (p_cynara)
+       pthread_mutex_lock(&g_cynara_mutex);
+       if (p_cynara) {
+               SLOG(LOG_ERROR, TAG_VCM, "[DEBUG] cynara finish");
                cynara_finish(p_cynara);
+       }
        p_cynara = NULL;
+       pthread_mutex_unlock(&g_cynara_mutex);
 }
 
 static int __vc_mgr_check_privilege()
@@ -216,6 +236,7 @@ static int __vc_mgr_check_privilege()
                __check_privilege_deinitialize();
        }
 
+       g_privilege_allowed = 1;
        return VC_ERROR_NONE;
 }
 
@@ -225,7 +246,7 @@ int vc_mgr_initialize(void)
 
 
        if (0 != __vc_mgr_get_feature_enabled()) {
-               SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
+               SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] not supported");
                return VC_ERROR_NOT_SUPPORTED;
        }
 
@@ -426,7 +447,7 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data)
                        vc_mgr_client_use_callback(g_vc_m);
                        service_changed_callback(previous_service_state, service_state, user_data);
                        vc_mgr_client_not_use_callback(g_vc_m);
-                       SLOG(LOG_DEBUG, TAG_VCM, "Service state changed callback is called");
+                       SLOG(LOG_INFO, TAG_VCM, "Service state changed callback is called");
                } else {
                        SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null");
                }
@@ -451,7 +472,7 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data)
                        vc_mgr_client_use_callback(g_vc_m);
                        changed_callback(before_state, current_state, user_data);
                        vc_mgr_client_not_use_callback(g_vc_m);
-                       SLOG(LOG_DEBUG, TAG_VCM, "State changed callback is called");
+                       SLOG(LOG_INFO, TAG_VCM, "State changed callback is called");
                } else {
                        SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null");
                }
@@ -460,7 +481,7 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data)
                return EINA_FALSE;
        }
 
-       SLOG(LOG_DEBUG, TAG_VCM, "@@@");
+       SLOG(LOG_ERROR, TAG_VCM, "@@@");
 
        return EINA_FALSE;
 }
@@ -482,7 +503,7 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
 
                ret = vc_mgr_dbus_request_hello();
                if (ret == 0) {
-                       SLOG(LOG_DEBUG, TAG_VCM, "Success to request hello. retry count(%d)", retry_count);
+                       SLOG(LOG_INFO, TAG_VCM, "Success to request hello. retry count(%d)", retry_count);
                        break;
                } else {
                        retry_count++;
@@ -508,7 +529,7 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
 
 static void __end_prepare_thread(void *data, Ecore_Thread *thread)
 {
-       SLOG(LOG_DEBUG, TAG_VCM, "@@@ End prepare thread");
+       SLOG(LOG_INFO, TAG_VCM, "@@@ End prepare thread");
 }
 
 int vc_mgr_prepare(void)
@@ -516,7 +537,7 @@ int vc_mgr_prepare(void)
        SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Prepare");
 
        if (0 != __vc_mgr_get_feature_enabled()) {
-               SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
+               SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] not supported");
                return VC_ERROR_NOT_SUPPORTED;
        }
 
@@ -538,7 +559,9 @@ int vc_mgr_prepare(void)
                return VC_ERROR_INVALID_STATE;
        }
 
+       ecore_thread_main_loop_begin();
        ecore_thread_run(__start_prepare_thread, __end_prepare_thread, NULL, NULL);
+       ecore_thread_main_loop_end();
 
        SLOG(LOG_DEBUG, TAG_VCM, "@@@");
 
index 7b7c432c290e509aa10e47d2e4cc638d7185d02d..68b78f28e3b5c33c391cb5214621233b5531e583 100644 (file)
@@ -95,7 +95,7 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd
                snprintf(if_name, 64, "%s", VC_MANAGER_SERVICE_INTERFACE);
 
                if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_HELLO)) {
-                       SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get Hello");
+                       SLOG(LOG_INFO, TAG_VCM, "@@@ Get Hello");
                        int pid = 0;
                        int response = -1;
 
@@ -121,7 +121,7 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd
                                if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
                                        SLOG(LOG_ERROR, TAG_VCM, "@@ vc get hello : fail to send reply");
                                else
-                                       SLOG(LOG_DEBUG, TAG_VCM, "@@ vc get hello : result(%d)", response);
+                                       SLOG(LOG_INFO, TAG_VCM, "@@ vc get hello : result(%d)", response);
 
                                dbus_connection_flush(g_m_conn_listener);
                                dbus_message_unref(reply);
@@ -162,7 +162,7 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd
                                dbus_error_free(&err);
                        }
 
-                       SLOG(LOG_DEBUG, TAG_VCM, "@@ state changed : %d", state);
+                       SLOG(LOG_INFO, TAG_VCM, "@@ state changed : %d", state);
 
                        __vc_mgr_cb_service_state(state);
 
@@ -271,7 +271,7 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd
                } /* VCD_MANAGER_METHOD_ALL_RESULT */
 
                else if (dbus_message_is_signal(msg, if_name, VCD_MANAGER_METHOD_ERROR)) {
-                       SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get Error");
+                       SLOG(LOG_INFO, TAG_VCM, "@@@ Get Error");
                        int reason;
                        int daemon_pid;
                        char* err_msg = NULL;
@@ -636,7 +636,7 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd
                } /* NameOwnerChanged */
 
                else {
-                       SLOG(LOG_DEBUG, TAG_VCM, "Message is NOT valid");
+                       SLOG(LOG_INFO, TAG_VCM, "Message is NOT valid");
                        dbus_message_unref(msg);
                        break;
                }
@@ -706,7 +706,7 @@ int vc_mgr_dbus_open_connection()
 
        dbus_connection_set_exit_on_disconnect(g_m_conn_listener, false);
 
-       SLOG(LOG_DEBUG, TAG_VCM, "service name is %s", VC_MANAGER_SERVICE_NAME);
+       SLOG(LOG_INFO, TAG_VCM, "service name is %s", VC_MANAGER_SERVICE_NAME);
 
        /* register our name on the bus, and check for errors */
        ret = dbus_bus_request_name(g_m_conn_listener, VC_MANAGER_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
@@ -801,14 +801,14 @@ int vc_mgr_dbus_reconnect()
                        return -1;
                }
 
-               SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect");
+               SLOG(LOG_INFO, TAG_VCM, "[DBUS] Reconnect");
                return 0;
        }
 
        bool sender_connected = dbus_connection_get_is_connected(g_m_conn_sender);
        bool listener_connected = dbus_connection_get_is_connected(g_m_conn_listener);
 
-       SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Sender(%s) Listener(%s)",
+       SLOG(LOG_INFO, TAG_VCM, "[DBUS] Sender(%s) Listener(%s)",
                 sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
 
        if (false == sender_connected || false == listener_connected) {
@@ -941,7 +941,7 @@ int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* servi
                SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr initialize : Fail to make message ");
                return VC_ERROR_OPERATION_FAILED;
        } else {
-               SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr initialize : pid(%d)", pid);
+               SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr initialize : pid(%d)", pid);
        }
 
        dbus_message_append_args(msg,
@@ -994,7 +994,7 @@ int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* servi
                                dbus_error_free(&err);
                        }
 
-                       SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr initialize : result = %d, service state = %d, foreground = %d, daemon_pid = %d",
+                       SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr initialize : result = %d, service state = %d, foreground = %d, daemon_pid = %d",
                                result, *service_state, *foreground, *daemon_pid);
                } else {
                        SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr initialize : result = %d", result);