]> code.delx.au - pulseaudio/blobdiff - src/modules/module-protocol-stub.c
* add new function pa_check_in_group()
[pulseaudio] / src / modules / module-protocol-stub.c
index 0ffd81df5da840e4b5a15c5f078dd5ebd9fd5b3b..ecbc5676ce488bd86cc28a5b1c12ccf4627d80a0 100644 (file)
@@ -1,20 +1,20 @@
 /* $Id$ */
 
 /***
-  This file is part of polypaudio.
+  This file is part of PulseAudio.
  
-  polypaudio is free software; you can redistribute it and/or modify
+  PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
   by the Free Software Foundation; either version 2 of the License,
   or (at your option) any later version.
  
-  polypaudio is distributed in the hope that it will be useful, but
+  PulseAudio is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.
  
   You should have received a copy of the GNU Lesser General Public License
-  along with polypaudio; if not, write to the Free Software
+  along with PulseAudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 ***/
 #include <netinet/in.h>
 #endif
 
-#include "../polypcore/winsock.h"
+#include "../pulsecore/winsock.h"
 
-#include <polypcore/module.h>
-#include <polypcore/socket-server.h>
-#include <polypcore/socket-util.h>
-#include <polypcore/util.h>
-#include <polypcore/modargs.h>
-#include <polypcore/log.h>
-#include <polypcore/native-common.h>
-#include <polypcore/xmalloc.h>
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/core-error.h>
+#include <pulsecore/module.h>
+#include <pulsecore/socket-server.h>
+#include <pulsecore/socket-util.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/modargs.h>
+#include <pulsecore/log.h>
+#include <pulsecore/native-common.h>
+#include <pulsecore/creds.h>
 
 #ifdef USE_TCP_SOCKETS
 #define SOCKET_DESCRIPTION "(TCP sockets)"
-#define SOCKET_USAGE "port=<TCP port number> loopback=<listen on loopback device only?> listen=<address to listen on>"
+#define SOCKET_USAGE "port=<TCP port number> listen=<address to listen on>"
 #else
 #define SOCKET_DESCRIPTION "(UNIX sockets)"
 #define SOCKET_USAGE "socket=<path to UNIX socket>"
 #endif
 
 #if defined(USE_PROTOCOL_SIMPLE)
-  #include <polypcore/protocol-simple.h>
+  #include <pulsecore/protocol-simple.h>
   #define protocol_new pa_protocol_simple_new
   #define protocol_free pa_protocol_simple_free
-  #define TCPWRAP_SERVICE "polypaudio-simple"
+  #define TCPWRAP_SERVICE "pulseaudio-simple"
   #define IPV4_PORT 4711
   #define UNIX_SOCKET "simple"
   #define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
     #include "module-simple-protocol-unix-symdef.h"
   #endif
   PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION)
-  PA_MODULE_USAGE("rate=<sample rate> format=<sample format> channels=<number of channels> sink=<sink to connect to> source=<source to connect to> playback=<enable playback?> record=<enable record?> "SOCKET_USAGE)
+  PA_MODULE_USAGE("rate=<sample rate> "
+                  "format=<sample format> "
+                  "channels=<number of channels> "
+                  "sink=<sink to connect to> "
+                  "source=<source to connect to> "
+                  "playback=<enable playback?> "
+                  "record=<enable record?> "
+                  SOCKET_USAGE)
 #elif defined(USE_PROTOCOL_CLI)
-  #include <polypcore/protocol-cli.h> 
+  #include <pulsecore/protocol-cli.h> 
   #define protocol_new pa_protocol_cli_new
   #define protocol_free pa_protocol_cli_free
-  #define TCPWRAP_SERVICE "polypaudio-cli"
+  #define TCPWRAP_SERVICE "pulseaudio-cli"
   #define IPV4_PORT 4712
   #define UNIX_SOCKET "cli"
   #define MODULE_ARGUMENTS 
   PA_MODULE_DESCRIPTION("Command line interface protocol "SOCKET_DESCRIPTION)
   PA_MODULE_USAGE(SOCKET_USAGE)
 #elif defined(USE_PROTOCOL_HTTP)
-  #include <polypcore/protocol-http.h>
+  #include <pulsecore/protocol-http.h>
   #define protocol_new pa_protocol_http_new
   #define protocol_free pa_protocol_http_free
-  #define TCPWRAP_SERVICE "polypaudio-http"
+  #define TCPWRAP_SERVICE "pulseaudio-http"
   #define IPV4_PORT 4714
   #define UNIX_SOCKET "http"
   #define MODULE_ARGUMENTS 
   PA_MODULE_DESCRIPTION("HTTP "SOCKET_DESCRIPTION)
   PA_MODULE_USAGE(SOCKET_USAGE)
 #elif defined(USE_PROTOCOL_NATIVE)
-  #include <polypcore/protocol-native.h>
+  #include <pulsecore/protocol-native.h>
   #define protocol_new pa_protocol_native_new
   #define protocol_free pa_protocol_native_free
-  #define TCPWRAP_SERVICE "polypaudio-native"
+  #define TCPWRAP_SERVICE "pulseaudio-native"
   #define IPV4_PORT PA_NATIVE_DEFAULT_PORT
   #define UNIX_SOCKET PA_NATIVE_DEFAULT_UNIX_SOCKET
   #define MODULE_ARGUMENTS_COMMON "cookie", "auth-anonymous",
     #include "module-native-protocol-unix-symdef.h"
   #endif
 
-  #if defined(SCM_CREDENTIALS) && !defined(USE_TCP_SOCKETS)
-    #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group",
-    #define AUTH_USAGE "auth-group=<local group to allow access>"
+  #if defined(HAVE_CREDS) && !defined(USE_TCP_SOCKETS)
+    #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON "auth-group", "auth-group-enable="
+    #define AUTH_USAGE "auth-group=<system group to allow access> auth-group-enable=<enable auth by UNIX group?> "
   #else
     #define MODULE_ARGUMENTS MODULE_ARGUMENTS_COMMON
     #define AUTH_USAGE
   #endif
   
   PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION)
-  PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> cookie=<path to cookie file> "AUTH_USAGE SOCKET_USAGE)
+  PA_MODULE_USAGE("auth-anonymous=<don't check for cookies?> "
+                  "cookie=<path to cookie file> "
+                  AUTH_USAGE
+                  SOCKET_USAGE)
 #elif defined(USE_PROTOCOL_ESOUND)
-  #include <polypcore/protocol-esound.h>
-  #include <polypcore/esound.h>
+  #include <pulsecore/protocol-esound.h>
+  #include <pulsecore/esound.h>
   #define protocol_new pa_protocol_esound_new
   #define protocol_free pa_protocol_esound_free
   #define TCPWRAP_SERVICE "esound"
     #include "module-esound-protocol-unix-symdef.h"
   #endif
   PA_MODULE_DESCRIPTION("ESOUND protocol "SOCKET_DESCRIPTION)
-  PA_MODULE_USAGE("sink=<sink to connect to> source=<source to connect to> auth-anonymous=<don't check for cookies?> cookie=<path to cookie file> "SOCKET_USAGE)
+  PA_MODULE_USAGE("sink=<sink to connect to> "
+                  "source=<source to connect to> "
+                  "auth-anonymous=<don't verify cookies?> "
+                  "cookie=<path to cookie file> "
+                  SOCKET_USAGE)
 #else
   #error "Broken build system" 
 #endif
@@ -155,7 +172,6 @@ static const char* const valid_modargs[] = {
     MODULE_ARGUMENTS
 #if defined(USE_TCP_SOCKETS)
     "port",
-    "loopback",
     "listen",
 #else
     "socket",
@@ -169,6 +185,7 @@ struct userdata {
     void *protocol_ipv6;
 #else
     void *protocol_unix;
+    char *socket_path;
 #endif
 };
 
@@ -180,13 +197,11 @@ int pa__init(pa_core *c, pa_module*m) {
 
 #if defined(USE_TCP_SOCKETS)
     pa_socket_server *s_ipv4 = NULL, *s_ipv6 = NULL;
-    int loopback = 1;
     uint32_t port = IPV4_PORT;
     const char *listen_on;
 #else
     pa_socket_server *s;
     int r;
-    const char *v;
     char tmp[PATH_MAX];
 #endif
 
@@ -197,12 +212,9 @@ int pa__init(pa_core *c, pa_module*m) {
         goto finish;
     }
 
-#if defined(USE_TCP_SOCKETS)
-    if (pa_modargs_get_value_boolean(ma, "loopback", &loopback) < 0) {
-        pa_log(__FILE__": loopback= expects a boolean argument.");
-        goto fail;
-    }
+    u = pa_xnew0(struct userdata, 1);
 
+#if defined(USE_TCP_SOCKETS)
     if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) {
         pa_log(__FILE__": port= expects a numerical argument between 1 and 65535.");
         goto fail;
@@ -213,9 +225,6 @@ int pa__init(pa_core *c, pa_module*m) {
     if (listen_on) {
         s_ipv6 = pa_socket_server_new_ipv6_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE);
         s_ipv4 = pa_socket_server_new_ipv4_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE);
-    } else if (loopback) {
-        s_ipv6 = pa_socket_server_new_ipv6_loopback(c->mainloop, port, TCPWRAP_SERVICE);
-        s_ipv4 = pa_socket_server_new_ipv4_loopback(c->mainloop, port, TCPWRAP_SERVICE);
     } else {
         s_ipv6 = pa_socket_server_new_ipv6_any(c->mainloop, port, TCPWRAP_SERVICE);
         s_ipv4 = pa_socket_server_new_ipv4_any(c->mainloop, port, TCPWRAP_SERVICE);
@@ -224,19 +233,35 @@ int pa__init(pa_core *c, pa_module*m) {
     if (!s_ipv4 && !s_ipv6)
         goto fail;
 
+    if (s_ipv4)
+        if (!(u->protocol_ipv4 = protocol_new(c, s_ipv4, m, ma)))
+            pa_socket_server_unref(s_ipv4);
+
+    if (s_ipv6)
+        if (!(u->protocol_ipv6 = protocol_new(c, s_ipv6, m, ma)))
+            pa_socket_server_unref(s_ipv6);
+
+    if (!u->protocol_ipv4 && !u->protocol_ipv6)
+        goto fail;
+
 #else
-    v = pa_modargs_get_value(ma, "socket", UNIX_SOCKET);
-    assert(v);
 
-    pa_runtime_path(v, tmp, sizeof(tmp));
+    pa_runtime_path(pa_modargs_get_value(ma, "socket", UNIX_SOCKET), tmp, sizeof(tmp));
+    u->socket_path = pa_xstrdup(tmp);
+
+#if defined(USE_PROTOCOL_ESOUND)
 
-    if (pa_make_secure_parent_dir(tmp) < 0) {
-        pa_log(__FILE__": Failed to create secure socket directory.");
+    /* This socket doesn't reside in our own runtime dir but in
+     * /tmp/.esd/, hence we have to create the dir first */
+    
+    if (pa_make_secure_parent_dir(u->socket_path, c->is_system_instance ? 0755 : 0700, getuid(), getgid()) < 0) {
+        pa_log(__FILE__": Failed to create socket directory: %s\n", pa_cstrerror(errno));
         goto fail;
     }
-
+#endif
+    
     if ((r = pa_unix_socket_remove_stale(tmp)) < 0) {
-        pa_log(__FILE__": Failed to remove stale UNIX socket '%s': %s", tmp, strerror(errno));
+        pa_log(__FILE__": Failed to remove stale UNIX socket '%s': %s", tmp, pa_cstrerror(errno));
         goto fail;
     }
     
@@ -245,24 +270,10 @@ int pa__init(pa_core *c, pa_module*m) {
     
     if (!(s = pa_socket_server_new_unix(c->mainloop, tmp)))
         goto fail;
-#endif
-
-    u = pa_xnew0(struct userdata, 1);
 
-#if defined(USE_TCP_SOCKETS)
-    if (s_ipv4)
-        if (!(u->protocol_ipv4 = protocol_new(c, s_ipv4, m, ma)))
-            pa_socket_server_unref(s_ipv4);
-
-    if (s_ipv6)
-        if (!(u->protocol_ipv6 = protocol_new(c, s_ipv6, m, ma)))
-            pa_socket_server_unref(s_ipv6);
-
-    if (!u->protocol_ipv4 && !u->protocol_ipv6)
-        goto fail;
-#else
     if (!(u->protocol_unix = protocol_new(c, s, m, ma)))
         goto fail;
+
 #endif
 
     m->userdata = u;
@@ -285,7 +296,11 @@ fail:
 #else
         if (u->protocol_unix)
             protocol_free(u->protocol_unix);
+
+        if (u->socket_path)
+            pa_xfree(u->socket_path);
 #endif
+
         pa_xfree(u);
     } else {
 #if defined(USE_TCP_SOCKETS)
@@ -304,17 +319,11 @@ fail:
 
 void pa__done(pa_core *c, pa_module*m) {
     struct userdata *u;
-    assert(c && m);
-
-#if defined(USE_PROTOCOL_ESOUND) && !defined(USE_TCP_SOCKETS)
-    if (remove(ESD_UNIX_SOCKET_NAME) != 0)
-        pa_log("%s: Failed to remove %s : %s.", __FILE__, ESD_UNIX_SOCKET_NAME, strerror (errno));
-    if (remove(ESD_UNIX_SOCKET_DIR) != 0)
-        pa_log("%s: Failed to remove %s : %s.", __FILE__, ESD_UNIX_SOCKET_DIR, strerror (errno));
-#endif
+    
+    assert(c);
+    assert(m);
 
     u = m->userdata;
-    assert(u);
 
 #if defined(USE_TCP_SOCKETS)
     if (u->protocol_ipv4)
@@ -324,6 +333,17 @@ void pa__done(pa_core *c, pa_module*m) {
 #else
     if (u->protocol_unix)
         protocol_free(u->protocol_unix);
+
+#if defined(USE_PROTOCOL_ESOUND)
+    if (u->socket_path) {
+        char *p = pa_parent_dir(u->socket_path);
+        rmdir(p);
+        pa_xfree(p);
+    }
+#endif
+    
+    
+    pa_xfree(u->socket_path);
 #endif
 
     pa_xfree(u);