stream-manager: add restriction for accessing denied remote device 92/241192/7
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 18 Aug 2020 11:10:32 +0000 (20:10 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 20 Aug 2020 07:16:14 +0000 (07:16 +0000)
includes minor code refactoring

[Version] 13.0.26
[Issue Type] Update

Change-Id: I1d77ff249192bde15b861c9a9d481e3564b791d6

packaging/pulseaudio-modules-tizen.spec
src/stream-manager-restriction-priv.h
src/stream-manager-restriction.c
src/stream-manager.c

index 3d9e02b001faf0eadfdacd27daebf1d74aeeb4f4..06d9ceabb94d09cf67c3ec65c63f3e38007a8ee5 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          13.0.25
+Version:          13.0.26
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index bc1906d5ef24d97e80e19fabddaeefd63885abea..1e738e36592e1ef02b8542cad0230311cd47e83d 100644 (file)
 
 #include "stream-manager.h"
 
-/* dbus method args */
-#define STREAM_MANAGER_METHOD_ARGS_BLOCK_RECORDING_MEDIA     "block_recording_media"
-
 int32_t handle_restrictions(pa_stream_manager *m, const char *name, uint32_t value);
-bool check_restrictions(pa_stream_manager *m, void *stream, stream_type_t stream_type);
+bool is_restricted(pa_stream_manager *m, void *stream, stream_type_t stream_type);
+bool is_remote_restricted(void *stream, stream_type_t type);
 
 #endif
index 818b6c5c3529cb7a9ab4e857cc950fc5f9ee140f..27a91a63209dbfc4b7be8a18547f15bfc3405de5 100644 (file)
 #include <config.h>
 #endif
 
+#include <pulsecore/proplist-util.h>
+
 #include "stream-manager-priv.h"
 #include "stream-manager-restriction-priv.h"
 
+/* dbus method args */
+#define STREAM_MANAGER_METHOD_ARGS_BLOCK_RECORDING_MEDIA     "block_recording_media"
+
 int32_t handle_restrictions(pa_stream_manager *m, const char *name, uint32_t value) {
     const char *role;
     void *s;
@@ -33,33 +38,54 @@ int32_t handle_restrictions(pa_stream_manager *m, const char *name, uint32_t val
 
     pa_assert(m);
 
-    if (pa_safe_streq(name, STREAM_MANAGER_METHOD_ARGS_BLOCK_RECORDING_MEDIA) ) {
-        if (value == 1) {
-            pa_log_info("block MEDIA recording");
-            m->restrictions.block_recording_media = true;
-            PA_IDXSET_FOREACH(s, m->core->source_outputs, idx) {
-                role = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROLE);
-                if (pa_safe_streq(role, "media")) {
-                    pa_log_info("  -- kill source-output(%p, %u)", s, ((pa_source_output*)s)->index);
-                    pa_source_output_kill((pa_source_output*)s);
-                }
+    if (!pa_safe_streq(name, STREAM_MANAGER_METHOD_ARGS_BLOCK_RECORDING_MEDIA)) {
+        pa_log_error("unknown name : %s", pa_strnull(name));
+        return -1;
+    }
+
+    if (value == 1) {
+        pa_log_info("block MEDIA recording");
+        m->restrictions.block_recording_media = true;
+        PA_IDXSET_FOREACH(s, m->core->source_outputs, idx) {
+            role = pa_proplist_gets(GET_STREAM_PROPLIST(s, STREAM_SOURCE_OUTPUT), PA_PROP_MEDIA_ROLE);
+            if (pa_safe_streq(role, "media")) {
+                pa_log_info("  -- kill source-output(%p, %u)", s, ((pa_source_output*)s)->index);
+                pa_source_output_kill((pa_source_output*)s);
             }
-        } else if (value == 0) {
-            pa_log_info("MEDIA recording is now available");
-            m->restrictions.block_recording_media = false;
-        } else {
-            pa_log_error("unknown value");
-            return -1;
         }
+    } else if (value == 0) {
+        pa_log_info("MEDIA recording is now available");
+        m->restrictions.block_recording_media = false;
     } else {
-        pa_log_error("unknown name");
+        pa_log_error("unknown value : %u", value);
         return -1;
     }
 
     return 0;
 }
 
-bool check_restrictions(pa_stream_manager *m, void *stream, stream_type_t type) {
+bool is_remote_restricted(void *stream, stream_type_t type) {
+    pa_proplist* p = NULL;
+    if (type == STREAM_SOURCE_OUTPUT)
+        p = ((pa_source_output_new_data *)stream)->source->proplist;
+    else
+        p = ((pa_sink_input_new_data *)stream)->sink->proplist;
+
+    if (!pa_proplist_has_remote_name(p)) {
+        pa_log_debug("it is a local stream(%p)", stream);
+        return false;
+    }
+
+    if (pa_proplist_remote_is_allowed(p)) {
+        pa_log_info("stream(%p) is currently allowed", stream);
+        return false;
+    }
+
+    pa_log_warn("restricted due to denied remote access of stream(%p)!!!", stream);
+    return true;
+}
+
+bool is_restricted(pa_stream_manager *m, void *stream, stream_type_t type) {
     const char *role;
 
     pa_assert(m);
index 981d4c62cc6f40358e6f0d830acf29ac93535c38..f75e8f72d3e4f23aa77683743780797d1c0d13d0 100644 (file)
@@ -2480,6 +2480,8 @@ static pa_hook_result_t sink_input_new_cb(pa_core *core, pa_sink_input_new_data
     pa_log_debug("sink-input-new-data(%p)", new_data);
 
     process_stream(m, new_data, STREAM_SINK_INPUT, PROCESS_COMMAND_PREPARE, true);
+    if (is_remote_restricted(new_data, STREAM_SINK_INPUT))
+        return PA_HOOK_CANCEL;
     process_stream(m, new_data, STREAM_SINK_INPUT, PROCESS_COMMAND_UPDATE_BUFFER_ATTR, true);
     process_stream(m, new_data, STREAM_SINK_INPUT, PROCESS_COMMAND_UPDATE_VOLUME, true);
     process_stream(m, new_data, STREAM_SINK_INPUT, PROCESS_COMMAND_CHANGE_ROUTE_BY_STREAM_STARTED, true);
@@ -2635,7 +2637,8 @@ static pa_hook_result_t source_output_new_cb(pa_core *core, pa_source_output_new
     pa_log_debug("source-output-new-data(%p)", new_data);
 
     process_stream(m, new_data, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_PREPARE, true);
-    if (check_restrictions(m, new_data, STREAM_SOURCE_OUTPUT))
+    if (is_restricted(m, new_data, STREAM_SOURCE_OUTPUT) ||
+        is_remote_restricted(new_data, STREAM_SOURCE_OUTPUT))
         return PA_HOOK_CANCEL;
     process_stream(m, new_data, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_UPDATE_BUFFER_ATTR, true);
     process_stream(m, new_data, STREAM_SOURCE_OUTPUT, PROCESS_COMMAND_UPDATE_VOLUME, true);