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

index 710e378c071f3fc62b9654c4bca63c128895c970..89953187d308834c29638a2513ab754aa03d907d 100644 (file)
@@ -8,8 +8,8 @@ SET(description "Input Method APIs")
 SET(service "ui")
 SET(submodule "inputmethod")
 SET(remote_submodule "remote-input")
-SET(dependents "capi-base-common dlog evas eina ecore-imf ecore-wl2 libscl-core cynara-client cynara-session")
-SET(remote_dependents "capi-base-common dlog ecore-imf scim cynara-client cynara-session")
+SET(dependents "capi-base-common dlog evas eina ecore-imf ecore-wl2 libscl-core cynara-client cynara-session cynara-creds-self")
+SET(remote_dependents "capi-base-common dlog ecore-imf scim cynara-client cynara-session cynara-creds-self")
 SET(LIBDIR ${LIB_INSTALL_DIR})
 
 SET(Services
index ba71cfcb3798e66c80f8cc37a65d6c825ec5f54f..76011ce7f020976892d7ecba6f31a3eff6662a9a 100644 (file)
@@ -9,6 +9,7 @@
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <cynara-session.h>
+#include <cynara-creds-self.h>
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -44,27 +45,26 @@ inputmethod_cynara_finish(void)
 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("Error : 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);
-    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) {
         LOGW("Access denied. The result of cynara_check() : %d.", ret);
@@ -72,4 +72,3 @@ check_privilege(const char *uid, const char *privilege)
     }
     return true;
 }
-
index 0211f199d1195d03a409804712c1b8dee8b75a77..a2bf25a17085783196089d189612480788052f0e 100644 (file)
@@ -16,6 +16,7 @@ BuildRequires:  pkgconfig(libscl-core)
 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 2f8e76c422c2df9056b74c26b1db24fa544075fd..9b978e7757ff56f5cb9c8940189af899f096e4b1 100644 (file)
@@ -51,5 +51,6 @@ SET_TARGET_PROPERTIES(${UNITTEST_INPUTMETHOD} PROPERTIES
 --wrap=cynara_initialize,\
 --wrap=cynara_finish,\
 --wrap=cynara_session_from_pid,\
---wrap=cynara_check")
+--wrap=cynara_check,\
+--wrap=cynara_creds_self_get_client")
 INSTALL(TARGETS ${UNITTEST_INPUTMETHOD} DESTINATION /usr/bin)
index 503172e15ef6fb14450e3559111e6c29b2d06b65..a683e7ae8625d200d736498fd51328bb5b3c7af5 100644 (file)
@@ -33,4 +33,10 @@ 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;
+}
+
 //LCOV_EXCL_STOP
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
 }