[PATCH] tunnel-sink/source-new: add cookie argument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When connecting to a remote server your local generated authentication
cookie is used. If remote server's cookie is different from your local
one you aren't allowed to connect. You can use the cookie argument
or define a wider acl in remote server configuration for module-native-protocol.
---
 src/modules/module-tunnel-sink-new.c   | 14 +++++++++++---
 src/modules/module-tunnel-source-new.c | 13 +++++++++++--
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/modules/module-tunnel-sink-new.c b/src/modules/module-tunnel-sink-new.c
index cd7c39c..9344bed 100644
--- a/src/modules/module-tunnel-sink-new.c
+++ b/src/modules/module-tunnel-sink-new.c
@@ -56,7 +56,8 @@ PA_MODULE_USAGE(
         "format=<sample format> "
         "channels=<number of channels> "
         "rate=<sample rate> "
-        "channel_map=<channel map>"
+        "channel_map=<channel map> "
+        "cookie=<cookie file path>"
         );
 
 #define TUNNEL_THREAD_FAILED_MAINLOOP 1
@@ -82,6 +83,7 @@ struct userdata {
 
     bool connected;
 
+    char *cookie_file;
     char *remote_server;
     char *remote_sink_name;
 };
@@ -95,7 +97,7 @@ static const char* const valid_modargs[] = {
     "channels",
     "rate",
     "channel_map",
-   /* "cookie", unimplemented */
+    "cookie",
    /* "reconnect", reconnect if server comes back again - unimplemented */
     NULL,
 };
@@ -139,6 +141,9 @@ static void thread_func(void *userdata) {
         goto fail;
     }
 
+    if (u->cookie_file && pa_context_load_cookie_from_file(u->context, u->cookie_file) != 0)
+        pa_log_error("Can not load cookie file!");
+
     pa_context_set_state_callback(u->context, context_state_cb, u);
     if (pa_context_connect(u->context,
                            u->remote_server,
@@ -451,7 +456,7 @@ int pa__init(pa_module *m) {
         goto fail;
     }
     u->thread_mainloop_api = pa_mainloop_get_api(u->thread_mainloop);
-
+    u->cookie_file = pa_xstrdup(pa_modargs_get_value(ma, "cookie", NULL));
     u->remote_sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
 
     pa_thread_mq_init_thread_mainloop(&u->thread_mq, m->core->mainloop, u->thread_mainloop_api);
@@ -538,6 +543,9 @@ void pa__done(pa_module *m) {
     if (u->thread_mainloop)
         pa_mainloop_free(u->thread_mainloop);
 
+    if (u->cookie_file)
+        pa_xfree(u->cookie_file);
+
     if (u->remote_sink_name)
         pa_xfree(u->remote_sink_name);
 
diff --git a/src/modules/module-tunnel-source-new.c b/src/modules/module-tunnel-source-new.c
index c59c4d3..caf7d40 100644
--- a/src/modules/module-tunnel-source-new.c
+++ b/src/modules/module-tunnel-source-new.c
@@ -56,7 +56,8 @@ PA_MODULE_USAGE(
         "format=<sample format> "
         "channels=<number of channels> "
         "rate=<sample rate> "
-        "channel_map=<channel map>"
+        "channel_map=<channel map> "
+        "cookie=<cookie file path>"
         );
 
 #define TUNNEL_THREAD_FAILED_MAINLOOP 1
@@ -81,6 +82,7 @@ struct userdata {
     bool connected;
     bool new_data;
 
+    char *cookie_file;
     char *remote_server;
     char *remote_source_name;
 };
@@ -94,7 +96,7 @@ static const char* const valid_modargs[] = {
     "channels",
     "rate",
     "channel_map",
-   /* "cookie", unimplemented */
+    "cookie",
    /* "reconnect", reconnect if server comes back again - unimplemented */
     NULL,
 };
@@ -177,6 +179,9 @@ static void thread_func(void *userdata) {
         goto fail;
     }
 
+    if (u->cookie_file && pa_context_load_cookie_from_file(u->context, u->cookie_file) != 0)
+        pa_log_error("Can not load cookie file!");
+
     pa_context_set_state_callback(u->context, context_state_cb, u);
     if (pa_context_connect(u->context,
                            u->remote_server,
@@ -428,6 +433,7 @@ int pa__init(pa_module *m) {
         goto fail;
     }
     u->thread_mainloop_api = pa_mainloop_get_api(u->thread_mainloop);
+    u->cookie_file = pa_xstrdup(pa_modargs_get_value(ma, "cookie", NULL));
     u->remote_source_name = pa_xstrdup(pa_modargs_get_value(ma, "source", NULL));
 
     pa_thread_mq_init_thread_mainloop(&u->thread_mq, m->core->mainloop, u->thread_mainloop_api);
@@ -513,6 +519,9 @@ void pa__done(pa_module *m) {
     if (u->thread_mainloop)
         pa_mainloop_free(u->thread_mainloop);
 
+    if (u->cookie_file)
+        pa_xfree(u->cookie_file);
+
     if (u->remote_source_name)
         pa_xfree(u->remote_source_name);
 
-- 
1.8.4



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux