net-misc/sslh: upgrade to 1.18

This CL imports net-misc/sslh from upstream Gentoo with the following
modifications:
- Downgrade EAPI from 6 to 5
- Add src_prepare to apply patches via epatch
- Change KEYWORDS to "*"

BUG=chromium:760784
TEST=Trybot runs on paladin and release builders.
TEST=Test ssh and adb connection to a DUT.

Change-Id: Ie6f10c9ceb43aa0213b74bd77fc912e8a0a67470
Reviewed-on: https://chromium-review.googlesource.com/643553
Commit-Ready: Ben Chan <benchan@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/net-misc/sslh/Manifest b/net-misc/sslh/Manifest
index 5549234..9db5fe5 100644
--- a/net-misc/sslh/Manifest
+++ b/net-misc/sslh/Manifest
@@ -1 +1 @@
-DIST sslh-v1.17.tar.gz 45447 SHA256 4f3589ed36d8a21581268d53055240eee5e5adf02894a2ca7a6c9022f24b582a SHA512 13e9980f4af4111d1b7c695cc61f6a99dca0dbe6be6391a735ebcd15944094526761dbee1ee52d0a94bff689bd9eeefabe930fc0a515f2389bf0f44e0823a431 WHIRLPOOL ec535e0932ba9debe2a19d6bef81b7a1498c658720bbf2a4a472b7858b7db3062299de605c264bf7dcaad3e912028491f5380c64b8c379ff693243a0a1f9a39a
+DIST sslh-v1.18.tar.gz 53170 SHA256 1601a5b377dcafc6b47d2fbb8d4d25cceb83053a4adcc5874d501a2d5a7745ad SHA512 3f0f61c340b689fb30015d5c73d6c29398b5c6a115ae9089d0b3c0230e99c90049df03133e4b0c3668fbfe995ed40cd3543c5764171c57e632e75bd5c3548fea WHIRLPOOL 31ab991527072c6304770b40ad07ce62ad8642e4697ac1cbeadd9f6226522f40b858d0dc6657578df3adba0f92d8f85fd38ece199f347eec352f3a831c131b35
diff --git a/net-misc/sslh/files/sslh-1.18-systemd-generator.patch b/net-misc/sslh/files/sslh-1.18-systemd-generator.patch
new file mode 100644
index 0000000..476de2a
--- /dev/null
+++ b/net-misc/sslh/files/sslh-1.18-systemd-generator.patch
@@ -0,0 +1,26 @@
+https://patch-diff.githubusercontent.com/raw/yrutschle/sslh/pull/98
+--- a/Makefile
++++ b/Makefile
+@@ -27,6 +27,8 @@ CFLAGS ?=-Wall -g $(CFLAGS_COV)
+ LIBS=
+ OBJS=common.o sslh-main.o probe.o tls.o
+ 
++CONDITIONAL_TARGETS=
++
+ ifneq ($(strip $(USELIBWRAP)),)
+ 	LIBS:=$(LIBS) -lwrap
+ 	CPPFLAGS+=-DLIBWRAP
+@@ -54,10 +56,11 @@ endif
+ ifneq ($(strip $(USESYSTEMD)),)
+         LIBS:=$(LIBS) -lsystemd
+         CPPFLAGS+=-DSYSTEMD
++	CONDITIONAL_TARGETS+=systemd-sslh-generator
+ endif
+ 
+ 
+-all: sslh $(MAN) echosrv
++all: sslh $(MAN) echosrv $(CONDITIONAL_TARGETS)
+ 
+ .c.o: *.h
+ 	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
+
diff --git a/net-misc/sslh/files/sslh-1.18-version-deps.patch b/net-misc/sslh/files/sslh-1.18-version-deps.patch
new file mode 100644
index 0000000..c6108ff
--- /dev/null
+++ b/net-misc/sslh/files/sslh-1.18-version-deps.patch
@@ -0,0 +1,15 @@
+Make sure the files using version.h depend on it being generated first.
+
+Gentoo-bug: 594586
+
+--- a/Makefile
++++ b/Makefile
+@@ -59,7 +59,7 @@
+ 
+ all: sslh $(MAN) echosrv
+ 
+-.c.o: *.h
++%.o: %.c *.h version.h
+ 	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
+ 
+ version.h:
diff --git a/net-misc/sslh/files/sslh.conf.d-2 b/net-misc/sslh/files/sslh.conf.d-2
index 719be7b..73d08d5 100644
--- a/net-misc/sslh/files/sslh.conf.d-2
+++ b/net-misc/sslh/files/sslh.conf.d-2
@@ -1,8 +1,8 @@
 # /etc/conf.d/sslh
 
 # Options to sslh itself.  See the sslh(1) man page.
-#OPTIONS=""
+#DAEMON_OPTS=""
 
 # Multiplexing example
 # Port 44 can be used for ssh, http, and https. Drop privileges after starting.
-#OPTIONS="-p localhost:44 --ssh 127.0.0.1:22 --http 127.0.0.1:80 --ssl 127.0.0.1:443 --user nobody"
+#DAEMON_OPTS="-p localhost:44 --ssh 127.0.0.1:22 --http 127.0.0.1:80 --ssl 127.0.0.1:443 --user nobody"
diff --git a/net-misc/sslh/files/sslh.init.d-2 b/net-misc/sslh/files/sslh.init.d-2
index 6122903..7e4b2cb 100755
--- a/net-misc/sslh/files/sslh.init.d-2
+++ b/net-misc/sslh/files/sslh.init.d-2
@@ -1,14 +1,13 @@
-#!/sbin/runscript
+#!/sbin/openrc-run
 # Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/net-misc/sslh/files/sslh.init.d-2,v 1.2 2012/07/11 15:47:57 kensington Exp $
 
 start() {
 	ebegin "Starting ${SVCNAME}"
 	start-stop-daemon --start \
 		--pidfile /var/run/${SVCNAME}.pid \
 		--exec /usr/sbin/sslh -- \
-			${OPTIONS} \
+			${DAEMON_OPTS} \
 			--pidfile /var/run/${SVCNAME}.pid
 	eend $?
 }
diff --git a/net-misc/sslh/metadata.xml b/net-misc/sslh/metadata.xml
index 07339f6..69570e8 100644
--- a/net-misc/sslh/metadata.xml
+++ b/net-misc/sslh/metadata.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
 <pkgmetadata>
-	<maintainer>
+	<maintainer type="person">
 		<email>kensington@gentoo.org</email>
 	</maintainer>
 </pkgmetadata>
diff --git a/net-misc/sslh/sslh-1.17.ebuild b/net-misc/sslh/sslh-1.17.ebuild
deleted file mode 100644
index d34e605..0000000
--- a/net-misc/sslh/sslh-1.17.ebuild
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright 1999-2015 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/net-misc/sslh/sslh-1.17.ebuild,v 1.1 2015/03/10 13:44:52 kensington Exp $
-
-EAPI=5
-
-MY_P="${PN}-v${PV}"
-inherit toolchain-funcs
-
-DESCRIPTION="Port multiplexer - accept both HTTPS and SSH connections on the same port"
-HOMEPAGE="http://www.rutschle.net/tech/sslh.shtml"
-SRC_URI="http://www.rutschle.net/tech/${MY_P}.tar.gz"
-
-LICENSE="GPL-2"
-SLOT="0"
-KEYWORDS="*"
-IUSE="caps tcpd"
-
-RDEPEND="caps? ( sys-libs/libcap )
-	tcpd? ( sys-apps/tcp-wrappers )
-	dev-libs/libconfig"
-DEPEND="${RDEPEND}"
-
-RESTRICT="test"
-
-S=${WORKDIR}/${MY_P}
-
-src_compile() {
-	emake \
-		CC="$(tc-getCC)" \
-		USELIBCAP=$(usev caps) \
-		USELIBWRAP=$(usev tcpd)
-}
-
-src_install() {
-	dosbin sslh-{fork,select}
-	dosym sslh-fork /usr/sbin/sslh
-	doman sslh.8.gz
-	dodoc ChangeLog README.md
-
-	newinitd "${FILESDIR}"/sslh.init.d-2 sslh
-	newconfd "${FILESDIR}"/sslh.conf.d-2 sslh
-}
diff --git a/net-misc/sslh/sslh-1.18-r2.ebuild b/net-misc/sslh/sslh-1.18-r2.ebuild
new file mode 100644
index 0000000..1d8aad4
--- /dev/null
+++ b/net-misc/sslh/sslh-1.18-r2.ebuild
@@ -0,0 +1,72 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+MY_P="${PN}-v${PV}"
+inherit eutils flag-o-matic systemd toolchain-funcs
+
+DESCRIPTION="Port multiplexer - accept both HTTPS and SSH connections on the same port"
+HOMEPAGE="http://www.rutschle.net/tech/sslh.shtml"
+SRC_URI="http://www.rutschle.net/tech/${PN}/${MY_P}.tar.gz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="*"
+IUSE="caps systemd tcpd"
+
+RDEPEND="caps? ( sys-libs/libcap )
+	systemd? ( sys-apps/systemd:= )
+	tcpd? ( sys-apps/tcp-wrappers )
+	>=dev-libs/libconfig-1.5"
+DEPEND="${RDEPEND}
+	dev-lang/perl"
+
+RESTRICT="test"
+
+S=${WORKDIR}/${MY_P}
+
+PATCHES=(
+	"${FILESDIR}/${PN}-1.18-version-deps.patch"
+	"${FILESDIR}/${PN}-1.18-systemd-generator.patch"
+)
+
+src_prepare() {
+	epatch "${PATCHES[@]}"
+}
+
+src_compile() {
+	# On older versions of GCC, the default gnu89 variant
+	# will reject within-for-loop initializers, bug #595426
+	# Furthermore, we need to use the gnu variant (gnu99) instead
+	# of the ISO (c99) variant, as we want the __USE_XOPEN2K macro
+	# to be defined.
+	append-cflags -std=gnu99
+
+	emake \
+		CC="$(tc-getCC)" \
+		USELIBCAP=$(usev caps) \
+		USELIBWRAP=$(usev tcpd) \
+		USESYSTEMD=$(usev systemd)
+}
+
+src_install() {
+	dosbin sslh-{fork,select}
+	dosym sslh-fork /usr/sbin/sslh
+
+	gunzip ${PN}.8.gz
+	doman ${PN}.8
+
+	dodoc ChangeLog README.md
+
+	newinitd "${FILESDIR}"/sslh.init.d-2 sslh
+	newconfd "${FILESDIR}"/sslh.conf.d-2 sslh
+
+	if use systemd; then
+		# Gentoo puts the binaries in /usr/sbin, but upstream puts them in /usr/bin
+		sed -i -e 's~/usr/bin/~/usr/sbin/~g' scripts/systemd.sslh.service || die
+		systemd_newunit scripts/systemd.sslh.service sslh.service
+		exeinto /usr/lib/systemd/system-generators/
+		doexe systemd-sslh-generator
+	fi
+}