Change method to check privilege 40/317640/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Mon, 6 Jan 2025 07:40:12 +0000 (16:40 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 6 Jan 2025 07:40:12 +0000 (16:40 +0900)
Change-Id: Ia4a5687c5a24e5ca2af9754b996d0cd241b6f4f1
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
CMakeLists.txt
packaging/capi-ui-inputmethod-manager.spec
src/privilege_checker.cpp
tests/CMakeLists.txt
tests/src/cynara_mock.cpp
tests/src/cynara_mock.h

index 48e21e14ccc124d6a86c2270afa730963fd3ec1c..9aff3578894dc6f0e1e83937c3326f9c06962083 100644 (file)
@@ -7,7 +7,7 @@ SET(maintainer "Sungmin Kwak <sungmin.kwak@samsung.com>")
 SET(description "Input Method Manager APIs")
 SET(service "ui")
 SET(submodule "inputmethod-manager")
-SET(dependents "capi-base-common dlog isf cynara-client cynara-session")
+SET(dependents "capi-base-common dlog isf cynara-client cynara-session cynara-creds-self")
 SET(LIBDIR ${LIB_INSTALL_DIR})
 
 SET(Services
index c2c1f5fbb156cdef6f03cc45b11ef613af8b152e..053924e2f4f9ae372017317da571240c09b016bc 100644 (file)
@@ -11,6 +11,7 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(isf)
 BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
+BuildRequires:  pkgconfig(cynara-creds-self)
 BuildRequires:  pkgconfig(gmock)
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index 37971a5aa5f5c1e8ae6dca2401bfb71954ce190b..24dfabfe27c5aa0afcf0a3d1cdc9518d34f473cb 100644 (file)
@@ -8,8 +8,8 @@
 
 #include <cynara-client.h>
 #include <cynara-error.h>
-#include <cynara-creds-socket.h>
 #include <cynara-session.h>
+#include <cynara-creds-self.h>
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -43,30 +43,30 @@ inputmethod_cynara_finish()
 bool
 check_privilege(const char *uid, const char *privilege)
 {
-    FILE *fp = NULL;
-    char label_path[1024] = "/proc/self/attr/current";
-    char smack_label[1024] = {'\0', };
+    char *client_identification = NULL;
+    char *session = NULL;
+    int ret;
 
     if (!p_cynara) {
         return false;
     }
 
-    fp = fopen(label_path, "r");
-    if (fp != NULL) {
-        if (fread(smack_label, 1, sizeof(smack_label) - 1, fp) <= 0) {
-            LOGW("[check_privilege] fail to fread");
-        }
-        fclose(fp);
+    if (cynara_creds_self_get_client(CLIENT_METHOD_DEFAULT, &client_identification) != CYNARA_API_SUCCESS) {
+        LOGW("Failed to get client.");
+        return false;
     }
 
-    pid_t pid = getpid();
-    char *session = cynara_session_from_pid(pid);
-    int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
-    LOGD("[check_privilege]_check_privilege returned %d.", ret);
-    if (session)
-        free(session);
+    session = cynara_session_from_pid(getpid());
+    ret = cynara_check(p_cynara, client_identification, session, uid, privilege);
+
+    free(session);
+    session = NULL;
+    free(client_identification);
+    client_identification= NULL;
 
-    if (ret != CYNARA_API_ACCESS_ALLOWED)
+    if (ret != CYNARA_API_ACCESS_ALLOWED) {
+        LOGW("Access denied. The result of cynara_check() : %d.", ret);
         return false;
+    }
     return true;
 }
index f8027775b82115875df2a00614ed3ffc6c9a8a57..dce0a7e9753880db9624685a0d0967fbde55b75b 100644 (file)
@@ -48,5 +48,6 @@ SET_TARGET_PROPERTIES(${UNITTEST_INPUTMETHOD_MANAGER} PROPERTIES
 --wrap=isf_control_is_ime_enabled,\
 --wrap=isf_control_get_all_ime_info,\
 --wrap=isf_control_get_active_ime,\
---wrap=isf_control_prelaunch_ise")
+--wrap=isf_control_prelaunch_ise,\
+--wrap=cynara_creds_self_get_client")
 INSTALL(TARGETS ${UNITTEST_INPUTMETHOD_MANAGER} DESTINATION /usr/bin)
index ff6e88fe23fd50ae31bceb76b92db2665d8d4e16..4abf476fa43d3c2d15b23a23568f1813a5fa0b65 100644 (file)
@@ -32,3 +32,8 @@ EXPORT_API char *__wrap_cynara_session_from_pid(pid_t pid)
 {
     return strdup("session");
 }
+
+EXPORT_API int __wrap_cynara_creds_self_get_client(enum cynara_client_creds method, char **client)
+{
+    return 0;
+}
index 1becb425d2d637ef29029c5902bf7e8a7e170778..ce9e7e169c013ecc35dc1c6c3ecdab4fc4103ad1 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <sys/types.h>
 #include <unistd.h>
+#include <cynara-creds-self.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -80,6 +81,7 @@ int __wrap_cynara_check(cynara* c, const char* client, const char* client_sessio
                         const char* privilege);
 
 char *__wrap_cynara_session_from_pid(pid_t pid);
+int __wrap_cynara_creds_self_get_client(enum cynara_client_creds method, char **client);
 
 #ifdef __cplusplus
 }