Adopt cynara api to check privilege 61/317861/1
authorsungwook79.park <sungwook79.park@samsung.com>
Thu, 9 Jan 2025 05:35:59 +0000 (14:35 +0900)
committersungwook79.park <sungwook79.park@samsung.com>
Thu, 9 Jan 2025 05:35:59 +0000 (14:35 +0900)
Change-Id: I8920254017e50f827b631839d54b2452ac0ca2b3
Signed-off-by: sungwook79.park <sungwook79.park@samsung.com>
CMakeLists.txt
packaging/voice-control-elm.spec
src/vc_elm.c
tests/CMakeLists.txt
tests/src/cynara_mock.cpp
tests/src/cynara_mock.h

index 8cf8b90d4c95a3960ef8481fc1e0679b1393ab97..7dcf2dfe60626770e54177000cc336b1e98d8797 100644 (file)
@@ -16,7 +16,7 @@ SET(VERSION ${VERSION})
 # pkg config tool
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED
-               vconf
+               vconf cynara-client cynara-session cynara-creds-self
 )
 
 # Build type
index 5e9f87ecca2f8f6b47958e05420045a5a0ff8fc5..faa5a1baf00ce91f126aee88cc9f6aa00f1d7a3f 100644 (file)
@@ -14,6 +14,7 @@ BuildRequires:        pkgconfig(capi-base-common)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(cynara-client)
 BuildRequires: pkgconfig(cynara-session)
+BuildRequires:  pkgconfig(cynara-creds-self)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(ecore)
 BuildRequires: pkgconfig(eina)
index 8ea910a44ff037b22352c103c834a3e926e461e2..a97d9f184286c3d010aaaf19690816ef07c06550 100644 (file)
@@ -17,6 +17,7 @@
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <cynara-session.h>
+#include <cynara-creds-self.h>
 #include <system_info.h>
 #include "vc_elm_main.h"
 #include <voice_control_elm.h>
@@ -120,31 +121,31 @@ static int __check_privilege_initialize()
 
 static int __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 (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
-                       VC_ELM_LOG_ERR("[ERROR] fail to fread"); //LCOV_EXCL_LINE
-
-               fclose(fp);
+       if (cynara_creds_self_get_client(CLIENT_METHOD_DEFAULT, &client_identification) != CYNARA_API_SUCCESS) {
+               VC_ELM_LOG_ERR("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);
-       VC_ELM_LOG_DBG("[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
-       if (session)
-               free(session);
+       session = cynara_session_from_pid(getpid());
+       ret = cynara_check(p_cynara, client_identification, session, uid, privilege);
 
-       if (ret != CYNARA_API_ACCESS_ALLOWED)
+       free(session);
+       session = NULL;
+       free(client_identification);
+       client_identification = NULL;
+
+       if (ret != CYNARA_API_ACCESS_ALLOWED) {
+               VC_ELM_LOG_ERR("[Client]cynara_check returned %d(Denied)", ret);
                return false;
+       }
        return true;
 }
 
index 5dcf596985dbddb0d5409803b41df1750ee72cbe..239619c7f90a95e950b43eec7f04d41065aa9e9d 100644 (file)
@@ -13,6 +13,7 @@ pkg_check_modules(test_pkgs REQUIRED
        ecore
        dlog
        gmock
+       cynara-creds-self
 )
 
 FOREACH(flag ${test_pkgs_CFLAGS})
@@ -48,6 +49,7 @@ SET_TARGET_PROPERTIES(${UNITTEST_VC_ELM} PROPERTIES
 --wrap=cynara_initialize,\
 --wrap=cynara_finish,\
 --wrap=cynara_session_from_pid,\
+--wrap=cynara_creds_self_get_client,\
 --wrap=cynara_check")
 
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/tests/${PKGNAME}.xml DESTINATION ${TZ_SYS_RO_PACKAGES})
index 858ebac46e6628d39f0683ab652b047d8c006e38..7c8217c741a5e1d78466997af11d32ae412d011f 100644 (file)
@@ -40,3 +40,8 @@ EXPORT_API char *__wrap_cynara_session_from_pid(pid_t pid)
        (void)pid;
        return strdup("session");
 }
+
+EXPORT_API int __wrap_cynara_creds_self_get_client(enum cynara_client_creds method, char **client)
+{
+    return 0;
+}
\ No newline at end of file
index 4f69b0583627e000aeb620c86fcf3e59a71bd3b7..3fba30bf45751023ac01e6e8d95f9e49f7246dbb 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
 }