From: Jihoon Kim Date: Mon, 6 Jan 2025 07:08:06 +0000 (+0900) Subject: Change method to check privilege X-Git-Tag: accepted/tizen/unified/20250107.102051~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f08bd910dfe1ba70f57b2ecea02f24d9ddaab80c;p=platform%2Fcore%2Fapi%2Finputmethod.git Change method to check privilege Change-Id: Ifd4b92e84f09667862dcf41c7f3333973370b24d Signed-off-by: Jihoon Kim --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 710e378..8995318 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/inputmethod/src/privilege_checker.cpp b/inputmethod/src/privilege_checker.cpp index ba71cfc..76011ce 100644 --- a/inputmethod/src/privilege_checker.cpp +++ b/inputmethod/src/privilege_checker.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #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; } - diff --git a/packaging/capi-ui-inputmethod.spec b/packaging/capi-ui-inputmethod.spec index 0211f19..a2bf25a 100644 --- a/packaging/capi-ui-inputmethod.spec +++ b/packaging/capi-ui-inputmethod.spec @@ -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 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2f8e76c..9b978e7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/src/cynara_mock.cpp b/tests/src/cynara_mock.cpp index 503172e..a683e7a 100644 --- a/tests/src/cynara_mock.cpp +++ b/tests/src/cynara_mock.cpp @@ -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 diff --git a/tests/src/cynara_mock.h b/tests/src/cynara_mock.h index 1becb42..ce9e7e1 100644 --- a/tests/src/cynara_mock.h +++ b/tests/src/cynara_mock.h @@ -3,6 +3,7 @@ #include #include +#include #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 }