feedback: Change to get smack label via cynara API 52/317652/1 accepted/tizen_unified accepted/tizen_unified_x accepted/tizen_unified_x_asan tizen accepted/tizen/unified/20250113.094323 accepted/tizen/unified/x/20250113.143058 accepted/tizen/unified/x/asan/20250211.003417
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 6 Jan 2025 07:27:29 +0000 (16:27 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 6 Jan 2025 07:54:51 +0000 (16:54 +0900)
Instead of reading '/proc/self/attr/current' directly, used
cynara_creds_self_get_client() API to get the smack label. It is
especially important at the environment with no-smack. The cynara
API has considered such case, so all we need to do is using the
cynara API.

Change-Id: I6ca7f493c1e710cc1645291aa3e61c6f16ebd3db
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
CMakeLists.txt
packaging/libfeedback.spec
src/util/feedback-privilege.c

index 40da24acf6194272954555013ccab2752712f2fa..6ae5db82ffd471abbbc8565c8a2bb74e2d9fd842 100644 (file)
@@ -49,6 +49,7 @@ pkg_check_modules(pkgs REQUIRED
                libsyscommon
                cynara-client
                cynara-session
+               cynara-creds-self
 )
 
 FOREACH(flag ${pkgs_CFLAGS})
index a088c136ff6ebef99c86e3b45081579527660f3a..6b8648e5f7009cc8f5448b30f1d045336aa0e9ff 100644 (file)
@@ -23,6 +23,7 @@ BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(libsyscommon)
 BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
+BuildRequires:  pkgconfig(cynara-creds-self)
 
 %if 0%{?gcov:1}
 BuildRequires: lcov
index 7bdf2de2fc0835b943a5b7195cc1e9772f94a93f..f82349314d6a133fefa649dca7482e289796ac43 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <cynara-client.h>
 #include <cynara-session.h>
+#include <cynara-creds-self.h>
 
 #include "util/feedback-privilege.h"
 #include "log.h"
@@ -34,10 +35,9 @@ extern char *program_invocation_name;
 bool is_privilege_supported(const char *privilege_name)
 {
        cynara *cynara = NULL;
-       FILE *fp = NULL;
        char uid[16];
        char *session = NULL;
-       char smack_label[BUFF_MAX] = {0, };
+       char *smack_label = NULL;
        int ret;
 
        if (cynara_initialize(&cynara, NULL) != CYNARA_API_SUCCESS) {
@@ -45,15 +45,10 @@ bool is_privilege_supported(const char *privilege_name)
                return false;
        }
 
-       fp = fopen("/proc/self/attr/current", "r");
-       if (fp != NULL) {
-               int ch = 0;
-               int idx = 0;
-               while (EOF != (ch = fgetc(fp))) {
-                       smack_label[idx] = ch;
-                       idx++;
-               }
-               fclose(fp);
+       ret = cynara_creds_self_get_client(CLIENT_METHOD_DEFAULT, &smack_label);
+       if (ret != CYNARA_API_SUCCESS) {
+               _E("failed to get smack label");
+               return false;
        }
 
        pid_t pid = getpid();
@@ -62,6 +57,8 @@ bool is_privilege_supported(const char *privilege_name)
        uid[15] = '\0';
 
        ret = cynara_check(cynara, smack_label, session, uid, privilege_name);
+       if (smack_label)
+               free(smack_label);
        if (session)
                free(session);
        if (cynara)