Commit Diff
Diff:
a78c7b3898e8f2b037fb42aac599ed8f8ec9bd58
5c6875d7686e1b4dbf1a82b6d159bd5f18da4a52
Commit:
5c6875d7686e1b4dbf1a82b6d159bd5f18da4a52
Tree:
afcb93d383379082e89de98654fddc55bd385b11
Author:
Alexander Barton <alex@barton.de>
Committer:
Alexander Barton <alex@barton.de>
Date:
Sun Feb 10 19:20:58 2013 UTC
Message:
Check type of sockets passed-in by systemd(8) This patch makes sure that ngIRCd doesn't try to handle sockets of unsupported types, for example of AF_INET6 sockets when ngIRCd isn't compiled with support for IPv6 ...
blob - cfa67eafb8bd7e9fdac8cfc75b390ee1620ee705
blob + be306e5f9a954238d001ec8ed470f412db2097c8
--- src/ngircd/conn.c
+++ src/ngircd/conn.c
@@ -532,8 +532,9 @@ Conn_InitListeners( void )
{
/* Initialize ports on which the server should accept connections */
unsigned int created = 0;
- char *copy, *listen_addr;
- int count, fd, i;
+ char *af_str, *copy, *listen_addr;
+ int count, fd, i, addr_len;
+ ng_ipaddr_t addr;
assert(Conf_ListenAddress);
@@ -549,6 +550,36 @@ Conn_InitListeners( void )
LogDebug("Initializing %d systemd sockets ...", count);
for (i = 0; i < count; i++) {
fd = SD_LISTEN_FDS_START + i;
+ addr_len = (int)sizeof(addr);
+ getsockname(fd, (struct sockaddr *)&addr, (socklen_t*)&addr_len);
+#ifdef WANT_IPV6
+ if (addr.sin4.sin_family != AF_INET && addr.sin4.sin_family != AF_INET6)
+#else
+ if (addr.sin4.sin_family != AF_INET)
+#endif
+ {
+ /* Socket is of unsupported type! For example, systemd passed in
+ * an IPv6 socket but ngIRCd isn't compiled with IPv6 support. */
+ switch (addr.sin4.sin_family)
+ {
+ case AF_UNSPEC: af_str = "AF_UNSPEC"; break;
+ case AF_UNIX: af_str = "AF_UNIX"; break;
+ case AF_INET: af_str = "AF_INET"; break;
+#ifdef AF_INET6
+ case AF_INET6: af_str = "AF_INET6"; break;
+#endif
+#ifdef AF_NETLINK
+ case AF_NETLINK: af_str = "AF_NETLINK"; break;
+#endif
+ default: af_str = "unknown"; break;
+ }
+ Log(LOG_CRIT,
+ "Socket %d is of unsupported type \"%s\" (%d), have to ignore it!",
+ fd, af_str, addr.sin4.sin_family);
+ close(fd);
+ continue;
+ }
+
Init_Socket(fd);
if (!io_event_create(fd, IO_WANTREAD, cb_listen)) {
Log(LOG_ERR,
IRCNow