summaryrefslogtreecommitdiffstats
path: root/polyp
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-09-29 20:13:05 +0000
committerLennart Poettering <lennart@poettering.net>2004-09-29 20:13:05 +0000
commit66999e5adaf54256718c638c3ad53acb0d74937b (patch)
treeb7890cf9f86d4e4b6b5d884e3f27136d3c2f0121 /polyp
parentd09240118ce0170c2fc5f504589646746902eb96 (diff)
Add support for libwrap
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@250 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp')
-rw-r--r--polyp/Makefile.am2
-rw-r--r--polyp/authkey.c5
-rw-r--r--polyp/main.c11
-rw-r--r--polyp/module-protocol-stub.c7
-rw-r--r--polyp/socket-server.c31
-rw-r--r--polyp/socket-server.h2
-rw-r--r--polyp/source.c2
7 files changed, 51 insertions, 9 deletions
diff --git a/polyp/Makefile.am b/polyp/Makefile.am
index 29b388c9..94d3373c 100644
--- a/polyp/Makefile.am
+++ b/polyp/Makefile.am
@@ -178,7 +178,7 @@ libprotocol_simple_la_LIBADD = $(AM_LIBADD) libsocket-server.la libiochannel.la
libsocket_server_la_SOURCES = socket-server.c socket-server.h
libsocket_server_la_LDFLAGS = -avoid-version
-libsocket_server_la_LIBADD = $(AM_LIBADD) libiochannel.la libsocket-util.la
+libsocket_server_la_LIBADD = $(AM_LIBADD) libiochannel.la libsocket-util.la $(LIBWRAP_LIBS)
libsocket_client_la_SOURCES = socket-client.c socket-client.h
libsocket_client_la_LDFLAGS = -avoid-version
diff --git a/polyp/authkey.c b/polyp/authkey.c
index c8d8576b..09a2c1b4 100644
--- a/polyp/authkey.c
+++ b/polyp/authkey.c
@@ -147,7 +147,7 @@ int pa_authkey_load(const char *path, void *data, size_t length) {
int pa_authkey_load_from_home(const char *fn, void *data, size_t length) {
char *home;
char path[PATH_MAX];
- char *p;
+ const char *p;
assert(fn && data && length);
@@ -155,7 +155,8 @@ int pa_authkey_load_from_home(const char *fn, void *data, size_t length) {
if (!(home = getenv("HOME")))
return -2;
- snprintf(p = path, sizeof(path), "%s/%s", home, fn);
+ snprintf(path, sizeof(path), "%s/%s", home, fn);
+ p = path;
} else
p = fn;
diff --git a/polyp/main.c b/polyp/main.c
index 0837e58d..25fb1741 100644
--- a/polyp/main.c
+++ b/polyp/main.c
@@ -34,6 +34,11 @@
#include <ltdl.h>
#include <memblock.h>
+#ifdef HAVE_LIBWRAP
+#include <syslog.h>
+#include <tcpd.h>
+#endif
+
#include "core.h"
#include "mainloop.h"
#include "module.h"
@@ -50,6 +55,12 @@
#include "caps.h"
#include "cli-text.h"
+#ifdef HAVE_LIBWRAP
+/* Only one instance of these variables */
+int allow_severity = LOG_INFO;
+int deny_severity = LOG_WARNING;
+#endif
+
static void signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
pa_log(__FILE__": Got signal %s.\n", pa_strsignal(sig));
diff --git a/polyp/module-protocol-stub.c b/polyp/module-protocol-stub.c
index fc1e9fd9..1ff70a1a 100644
--- a/polyp/module-protocol-stub.c
+++ b/polyp/module-protocol-stub.c
@@ -54,16 +54,17 @@ PA_MODULE_VERSION(PACKAGE_VERSION)
#include "protocol-simple.h"
#define protocol_new pa_protocol_simple_new
#define protocol_free pa_protocol_simple_free
+ #define TCPWRAP_SERVICE "polypaudio-simple"
#define IPV4_PORT 4711
#define UNIX_SOCKET "/tmp/polypaudio/simple"
#define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
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)
-
#elif defined(USE_PROTOCOL_CLI)
#include "protocol-cli.h"
#define protocol_new pa_protocol_cli_new
#define protocol_free pa_protocol_cli_free
+ #define TCPWRAP_SERVICE "polypaudio-cli"
#define IPV4_PORT 4712
#define UNIX_SOCKET "/tmp/polypaudio/cli"
#define MODULE_ARGUMENTS
@@ -73,6 +74,7 @@ PA_MODULE_VERSION(PACKAGE_VERSION)
#include "protocol-native.h"
#define protocol_new pa_protocol_native_new
#define protocol_free pa_protocol_native_free
+ #define TCPWRAP_SERVICE "polypaudio-native"
#define IPV4_PORT PA_NATIVE_DEFAULT_PORT
#define UNIX_SOCKET "/tmp/polypaudio/native"
#define MODULE_ARGUMENTS "public", "cookie",
@@ -83,6 +85,7 @@ PA_MODULE_VERSION(PACKAGE_VERSION)
#include "esound.h"
#define protocol_new pa_protocol_esound_new
#define protocol_free pa_protocol_esound_free
+ #define TCPWRAP_SERVICE "esound"
#define IPV4_PORT ESD_DEFAULT_PORT
#define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
#define MODULE_ARGUMENTS "sink", "source", "public", "cookie",
@@ -119,7 +122,7 @@ static struct pa_socket_server *create_socket_server(struct pa_core *c, struct p
return NULL;
}
- if (!(s = pa_socket_server_new_ipv4(c->mainloop, loopback ? INADDR_LOOPBACK : INADDR_ANY, port)))
+ if (!(s = pa_socket_server_new_ipv4(c->mainloop, loopback ? INADDR_LOOPBACK : INADDR_ANY, port, TCPWRAP_SERVICE)))
return NULL;
#else
int r;
diff --git a/polyp/socket-server.c b/polyp/socket-server.c
index 9f943dc0..c170bf6e 100644
--- a/polyp/socket-server.c
+++ b/polyp/socket-server.c
@@ -35,6 +35,10 @@
#include <netinet/in.h>
#include <arpa/inet.h>
+#ifdef HAVE_LIBWRAP
+#include <tcpd.h>
+#endif
+
#include "socket-server.h"
#include "socket-util.h"
#include "xmalloc.h"
@@ -45,6 +49,7 @@ struct pa_socket_server {
int ref;
int fd;
char *filename;
+ char *tcpwrap_service;
void (*on_connection)(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata);
void *userdata;
@@ -74,6 +79,23 @@ static void callback(struct pa_mainloop_api *mainloop, struct pa_io_event *e, in
goto finish;
}
+#ifdef HAVE_LIBWRAP
+
+ if (s->type == SOCKET_SERVER_IPV4 && s->tcpwrap_service) {
+ struct request_info req;
+
+ request_init(&req, RQ_DAEMON, s->tcpwrap_service, RQ_FILE, nfd, NULL);
+ fromhost(&req);
+ if (!hosts_access(&req)) {
+ pa_log(__FILE__": TCP connection refused by tcpwrap.\n");
+ close(nfd);
+ goto finish;
+ }
+
+ pa_log(__FILE__": TCP connection accepted by tcpwrap.\n");
+ }
+#endif
+
/* There should be a check for socket type here */
if (s->type == SOCKET_SERVER_IPV4)
pa_socket_tcp_low_delay(fd);
@@ -98,6 +120,7 @@ struct pa_socket_server* pa_socket_server_new(struct pa_mainloop_api *m, int fd)
s->filename = NULL;
s->on_connection = NULL;
s->userdata = NULL;
+ s->tcpwrap_service = NULL;
s->mainloop = m;
s->io_event = m->io_new(m, fd, PA_IO_EVENT_INPUT, callback, s);
@@ -159,7 +182,7 @@ fail:
return NULL;
}
-struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port) {
+struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port, const char *tcpwrap_service) {
struct pa_socket_server *ss;
int fd = -1;
struct sockaddr_in sa;
@@ -193,8 +216,10 @@ struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, ui
goto fail;
}
- if ((ss = pa_socket_server_new(m, fd)))
+ if ((ss = pa_socket_server_new(m, fd))) {
ss->type = SOCKET_SERVER_IPV4;
+ ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
+ }
return ss;
@@ -214,6 +239,8 @@ static void socket_server_free(struct pa_socket_server*s) {
pa_xfree(s->filename);
}
+ pa_xfree(s->tcpwrap_service);
+
s->mainloop->io_free(s->io_event);
pa_xfree(s);
}
diff --git a/polyp/socket-server.h b/polyp/socket-server.h
index c9d9193d..f5877e55 100644
--- a/polyp/socket-server.h
+++ b/polyp/socket-server.h
@@ -32,7 +32,7 @@ struct pa_socket_server;
struct pa_socket_server* pa_socket_server_new(struct pa_mainloop_api *m, int fd);
struct pa_socket_server* pa_socket_server_new_unix(struct pa_mainloop_api *m, const char *filename);
-struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port);
+struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port, const char *tcpwrap_service);
void pa_socket_server_unref(struct pa_socket_server*s);
struct pa_socket_server* pa_socket_server_ref(struct pa_socket_server *s);
diff --git a/polyp/source.c b/polyp/source.c
index 7df432d5..73645d49 100644
--- a/polyp/source.c
+++ b/polyp/source.c
@@ -143,7 +143,7 @@ void pa_source_post(struct pa_source*s, const struct pa_memchunk *chunk) {
assert(s && s->ref >= 1 && chunk);
pa_source_ref(s);
- pa_idxset_foreach(s->outputs, do_post, chunk);
+ pa_idxset_foreach(s->outputs, do_post, (void*) chunk);
pa_source_unref(s);
}