Adopt cynara api to check privilege 62/317862/1
authorsungwook79.park <sungwook79.park@samsung.com>
Thu, 9 Jan 2025 05:36:30 +0000 (14:36 +0900)
committersungwook79.park <sungwook79.park@samsung.com>
Thu, 9 Jan 2025 05:36:30 +0000 (14:36 +0900)
Change-Id: I05bb0e3b1396b364232b991bc2b3c2fa6cdd86d3
Signed-off-by: sungwook79.park <sungwook79.park@samsung.com>
CMakeLists.txt
client/ma.c
client/ma_ap.c
client/ma_ui.c
packaging/multi-assistant.spec
tests/CMakeLists.txt

index 1c2757bc45df61a6f17e0573aa1d9caa08fa1efa..4b76a7a31bbd05bcf39a91ab1a4b682f57740414 100644 (file)
@@ -43,7 +43,7 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include")
 ## Dependent packages ##
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED
-    capi-base-common capi-system-info cynara-client cynara-session dbus-1 dlog ecore bundle capi-message-port glib-2.0 json-glib-1.0 libtzplatform-config libxml-2.0 vconf
+    capi-base-common capi-system-info cynara-client cynara-session cynara-creds-self dbus-1 dlog ecore bundle capi-message-port glib-2.0 json-glib-1.0 libtzplatform-config libxml-2.0 vconf
 )
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_TRUSTED_MESSAGE_PORT=${USE_TRUSTED_MESSAGE_PORT}")
index 67d09160676cc080e22be91d40ba2119e97b5318..a01baa34477eee1baeb069b560aaf3a707401f82 100644 (file)
@@ -18,6 +18,7 @@
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <cynara-session.h>
+#include <cynara-creds-self.h>
 #include <system_info.h>
 #include <vconf/vconf.h>
 #include <stdlib.h>
@@ -123,31 +124,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))
-                       MA_SLOGE("[ERROR] fail to fread"); //LCOV_EXCL_LINE
-
-               fclose(fp);
+       if (cynara_creds_self_get_client(CLIENT_METHOD_DEFAULT, &client_identification) != CYNARA_API_SUCCESS) {
+               MA_SLOGE("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);
-       MA_SLOGD("[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied"); //LCOV_EXCL_LINE
-       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) {
+               MA_SLOGE("[Client]cynara_check returned %d(Denied)", ret);
                return false;
+       }
        return true;
 }
 
index de295e6302023cb1797cd70fc0db85632588646f..a8ce8d28133bd8b880b8ad2b01d7b74d48cfbf71 100644 (file)
@@ -18,6 +18,7 @@
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <cynara-session.h>
+#include <cynara-creds-self.h>
 #include <system_info.h>
 #include <vconf/vconf.h>
 #include <stdlib.h>
@@ -85,31 +86,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))
-                       MAAP_SLOGE("[ERROR] fail to fread"); //LCOV_EXCL_LINE
-
-               fclose(fp);
+       if (cynara_creds_self_get_client(CLIENT_METHOD_DEFAULT, &client_identification) != CYNARA_API_SUCCESS) {
+               MAAP_SLOGE("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);
-       MAAP_SLOGD("[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) {
+               MAAP_SLOGE("[Client]cynara_check returned %d(Denied)", ret);
                return false;
+       }
        return true;
 }
 
index 6257551577bd61dbdb35e17488b6ddcb6a265d09..bea0e02aa5268e4b5e402f5ebad8b18df5c8acf7 100644 (file)
@@ -19,6 +19,7 @@
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <cynara-session.h>
+#include <cynara-creds-self.h>
 #include <system_info.h>
 
 
@@ -89,31 +90,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))
-                       MAUI_SLOGE("[ERROR] fail to fread"); //LCOV_EXCL_LINE
-
-               fclose(fp);
+       if (cynara_creds_self_get_client(CLIENT_METHOD_DEFAULT, &client_identification) != CYNARA_API_SUCCESS) {
+               MAUI_SLOGE("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);
-       MAUI_SLOGD("[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) {
+               MAUI_SLOGE("[Client]cynara_check returned %d(Denied)", ret);
                return false;
+       }
        return true;
 }
 
index 5a4138bf854c3eaa0ff874840b3673c1af2eb469..092570790e24f27eccd4f520ea22fa8b385a4792 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(dbus-1)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(ecore)
index f2d0a4e3a256cca46f80537cc9090bb81d80cdd5..5570f28434c366f10ba275dddecd31ec9a79e66e 100644 (file)
@@ -21,6 +21,7 @@ pkg_check_modules(pkgs REQUIRED
        libxml-2.0
        vconf
        gmock
+       cynara-creds-self
 )
 
 FOREACH(flag ${pkgs_CFLAGS})