[core/angel]: support unix socket listen

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent 823b9d13c2
commit 14660bee4f
  1. 34
      src/angel/angel_plugin_core.c
  2. 32
      src/main/angel_fake.c

@ -9,6 +9,7 @@ typedef struct listen_ref_resource listen_ref_resource;
# define DEFAULT_LIBEXECDIR "/usr/local/lib/lighttpd2"
#endif
#include <fnmatch.h>
struct listen_socket {
gint refcount;
@ -384,7 +385,19 @@ static gboolean listen_check_acl(liServer *srv, liPluginCoreConfig *config, liSo
#ifdef HAVE_SYS_UN_H
case AF_UNIX: {
if (config->listen_masks->len) {
/* TODO: support unix addresses */
const gchar *fname = addr->addr->un.sun_path;
for (i = 0; i < config->listen_masks->len; i++) {
mask = g_ptr_array_index(config->listen_masks, i);
switch (mask->type) {
case LI_PLUGIN_CORE_LISTEN_MASK_UNIX:
if (fnmatch(mask->value.unix_socket.path->str, fname, FNM_PERIOD | FNM_PATHNAME)) continue;
return TRUE;
default:
continue;
}
}
return FALSE;
} else {
return FALSE; /* don't allow unix by default */
}
@ -466,9 +479,22 @@ static int do_listen(liServer *srv, liSocketAddress *addr, GString *str) {
#endif
#ifdef HAVE_SYS_UN_H
case AF_UNIX:
ERROR(srv, "Unix sockets not supported: %s", str->str);
/* TODO: support unix addresses */
break;
if (-1 == (s = socket(AF_UNIX, SOCK_STREAM, 0))) {
ERROR(srv, "Couldn't open socket: %s", g_strerror(errno));
return -1;
}
if (-1 == bind(s, &addr->addr->plain, addr->len)) {
close(s);
ERROR(srv, "Couldn't bind socket to '%s': %s", str->str, g_strerror(errno));
return -1;
}
if (-1 == listen(s, 1000)) {
close(s);
ERROR(srv, "Couldn't listen on '%s': %s", str->str, g_strerror(errno));
return -1;
}
DEBUG(srv, "listen to unix socket: '%s'", str->str);
return s;
#endif
default:
ERROR(srv, "Address family %i not supported", addr->addr->plain.sa_family);

@ -11,6 +11,38 @@ int li_angel_fake_listen(liServer *srv, GString *str) {
#endif
guint16 port;
#ifdef HAVE_SYS_UN_H
if (0 == strncmp(str->str, "unix:/", 6)) {
int s;
struct sockaddr_un *un;
socklen_t slen = str->len + 1 - 5 + sizeof(un->sun_family);
un = g_malloc0(slen);
un->sun_family = AF_UNIX;
strcpy(un->sun_path, str->str + 5);
if (-1 == (s = socket(AF_UNIX, SOCK_STREAM, 0))) {
ERROR(srv, "Couldn't open socket: %s", g_strerror(errno));
g_free(un);
return -1;
}
if (-1 == bind(s, (struct sockaddr*) un, slen)) {
close(s);
ERROR(srv, "Couldn't bind socket to '%s': %s", str->str, g_strerror(errno));
g_free(un);
return -1;
}
if (-1 == listen(s, 1000)) {
close(s);
ERROR(srv, "Couldn't listen on '%s': %s", str->str, g_strerror(errno));
g_free(un);
return -1;
}
g_free(un);
DEBUG(srv, "listen to unix socket: '%s'", str->str);
return s;
} else
#endif
if (li_parse_ipv4(str->str, &ipv4, NULL, &port)) {
int s, v;
struct sockaddr_in addr;

Loading…
Cancel
Save