Use cynara API to get smack label 87/317787/3
authorinkyun.kil <inkyun.kil@samsung.com>
Wed, 8 Jan 2025 01:35:22 +0000 (10:35 +0900)
committerinkyun.kil <inkyun.kil@samsung.com>
Thu, 6 Feb 2025 01:04:46 +0000 (10:04 +0900)
Change-Id: I08ee42a2aec0919dd33c9d960ac6414e504c615c
Signed-off-by: inkyun.kil <inkyun.kil@samsung.com>
daemon/CMakeLists.txt
daemon/daemon.c
packaging/buxton2.spec

index f8e51db39b6ccf638a01120f83dfa3957ed6a5a4..c2fa122041c0e6a2d9b6e0bcaf22d8e6961ee126 100644 (file)
@@ -1,6 +1,11 @@
 # buxton2d build
 
-PKG_CHECK_MODULES(D_PKGS REQUIRED libsystemd cynara-client-async gio-2.0)
+PKG_CHECK_MODULES(D_PKGS REQUIRED
+       libsystemd
+       cynara-client-async
+       cynara-creds-pid
+       gio-2.0
+)
 
 FOREACH(flag ${D_PKGS_CFLAGS})
        SET(DAEMON_CFLAGS "${DAEMON_CFLAGS} ${flag}")
index 13b02d7b1222f68ccdd50f4df5afa21449fe700e..2edf465faa06995dab295e00511e1424b667b947 100644 (file)
@@ -30,6 +30,8 @@
 #include <glib.h>
 #include <glib-unix.h>
 
+#include <cynara-creds-pid.h>
+
 #include "common.h"
 #include "log.h"
 #include "direct.h"
@@ -554,13 +556,10 @@ static void proc_get_priv(struct bxt_client *cli,
 
 static void update_label(gpointer key, gpointer value, gpointer user_data)
 {
-       int fd;
        int ret;
-       char buf[1024];
-       char path[1024];
-
        struct bxt_client *cli = (struct bxt_client *)value;
        int pid = *(int *)user_data;
+       char *client = NULL;
 
        if (cli->cred.pid != pid)
                return;
@@ -568,24 +567,15 @@ static void update_label(gpointer key, gpointer value, gpointer user_data)
        if (is_smack_disabled())
                return;
 
-       snprintf(path, sizeof(path), "/proc/%d/attr/current", cli->cred.pid);
-       fd = open(path, O_RDONLY);
-       if (fd < 0)
+       ret = cynara_creds_pid_get_client(cli->cred.pid, CLIENT_METHOD_DEFAULT, &client);
+       if (ret != CYNARA_API_SUCCESS) {
+               bxt_err("cynara_creds_pid_get_client [pid:%d][%d] failed!", cli->cred.pid, ret);
                return;
-
-       ret = read(fd, buf, sizeof(buf) - 1);
-       if (ret <= 0) {
-               close(fd);
-               return;
-       } else {
-               buf[ret] = 0;
        }
 
-       close(fd);
-
        if (cli->label)
                free(cli->label);
-       cli->label = strdup(buf);
+       cli->label = client;
 }
 
 static int update_client_label(struct bxt_client *cli)
index cd0edc70bdc6e2110840db6bc12f2082231883d2..7c0ec20b9911bb7080552d64f6c6fd3f4790b4e1 100644 (file)
@@ -19,6 +19,7 @@ BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(libsystemd)
 BuildRequires:  pkgconfig(cynara-client-async)
+BuildRequires:  pkgconfig(cynara-creds-pid)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(libtzplatform-config)