media_streamer_node: Use libsmack library to get the smack label 49/253349/1
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 9 Feb 2021 05:36:37 +0000 (14:36 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 9 Feb 2021 05:37:54 +0000 (14:37 +0900)
[Issue type] Improvement
[Version] 0.1.131

Change-Id: I9eed33f888817a52a6b83acdff51574754dceac7
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
CMakeLists.txt
packaging/capi-media-streamer.spec
src/media_streamer_node.c

index 3fe9f4a..4145dbd 100644 (file)
@@ -11,8 +11,8 @@ SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
 SET(dependents "dlog glib-2.0 mm-common capi-media-tool iniparser bundle libtbm gstreamer-1.0 gstreamer-plugins-base-1.0\
- gstreamer-app-1.0 gstreamer-video-1.0 gstreamer-sdp-1.0 gstreamer-webrtc-1.0 cynara-client capi-system-info ecore-evas\
- evas ecore-wl2 mm-resource-manager dpm capi-content-mime-type json-glib-1.0 libsoup-2.4")
+ gstreamer-app-1.0 gstreamer-video-1.0 gstreamer-sdp-1.0 gstreamer-webrtc-1.0 cynara-client libsmack\
capi-system-info ecore-evas evas ecore-wl2 mm-resource-manager dpm capi-content-mime-type json-glib-1.0 libsoup-2.4")
 SET(pc_dependents "capi-base-common capi-media-tool bundle")
 
 INCLUDE(FindPkgConfig)
index 7481fd7..2ed5db4 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-streamer
 Summary:    A Media Streamer API
-Version:    0.1.130
+Version:    0.1.131
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -36,6 +36,7 @@ BuildRequires:  pkgconfig(mm-resource-manager)
 BuildRequires:  pkgconfig(dpm)
 BuildRequires:  pkgconfig(libsoup-2.4)
 BuildRequires:  pkgconfig(capi-content-mime-type)
+BuildRequires:  pkgconfig(libsmack)
 
 %description
 A MediaStreamer library in Tizen Native API.
index 64e3dde..ae8be39 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <cynara-client.h>
 #include <system_info.h>
+#include <sys/smack.h>
 #include <Evas.h>
 #include <gst/video/videooverlay.h>
 #include "media_streamer_node.h"
@@ -731,12 +732,9 @@ static int __ms_node_check_privileges(media_streamer_node_s *node)
        int ret = MEDIA_STREAMER_ERROR_NONE;
        int ret_val = 0;
        char *privilege = NULL;
-       FILE* opened_file;
-       char smackLabel[SMACK_LABEL_LEN + 1];
        char uid[10];
        cynara *cynara_h = NULL;
-
-       ms_debug_fenter();
+       char *smack_label;
 
        ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL");
 
@@ -781,32 +779,17 @@ static int __ms_node_check_privileges(media_streamer_node_s *node)
        if (privilege == NULL)
                return ret;
 
-       if (CYNARA_API_SUCCESS != cynara_initialize(&cynara_h, NULL)) {
-               ms_error("Failed to initialize cynara structure\n");
-               return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
-       }
-
-       bzero(smackLabel, SMACK_LABEL_LEN + 1);
+       ms_retvm_if(cynara_initialize(&cynara_h, NULL) != CYNARA_API_SUCCESS, MEDIA_STREAMER_ERROR_INVALID_OPERATION,
+               "failed to cynara_initialize()");
 
-       /* Getting smack label */
-       opened_file = fopen("/proc/self/attr/current", "r");
-       if (opened_file == NULL) {
-               ms_error("Failed to open /proc/self/attr/current\n");
-               return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
-       }
-       ret_val = fread(smackLabel, sizeof(smackLabel), 1, opened_file);
-       fclose(opened_file);
-       if (ret_val < 0) {
-               ms_error("Failed to read /proc/self/attr/current\n");
-               return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
-       }
+       ms_retvm_if(smack_new_label_from_self(&smack_label) == -1, MEDIA_STREAMER_ERROR_INVALID_OPERATION,
+               "failed to smack_new_label_from_self()");
 
-       /* Getting uid */
        snprintf(uid, sizeof(uid), "%d", getuid());
-       ms_info("%s %s %s\n", smackLabel, uid, privilege);
+       ms_debug("smack_label[%s] uid[%s] privilege[%s]", smack_label, uid, privilege);
 
        /* Checking with cynara for current session */
-       ret_val = cynara_check(cynara_h, smackLabel, "", uid, privilege);
+       ret_val = cynara_check(cynara_h, smack_label, "", uid, privilege);
        ms_info("Cynara_check [%d] ", ret_val);
 
        switch (ret_val) {
@@ -822,7 +805,7 @@ static int __ms_node_check_privileges(media_streamer_node_s *node)
 
        cynara_finish(cynara_h);
 
-       ms_debug_fleave();
+       free(smack_label);
 
        return ret;
 }