rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/openssh-7.4p1-debian-restore-tcp-wrappers.patch

1d31ef
diff -up openssh-7.4p1/configure.ac.tcp_wrappers openssh-7.4p1/configure.ac
1d31ef
--- openssh-7.4p1/configure.ac.tcp_wrappers	2016-12-23 15:36:38.745411192 +0100
1d31ef
+++ openssh-7.4p1/configure.ac	2016-12-23 15:36:38.777411197 +0100
1d31ef
@@ -1491,6 +1491,62 @@ AC_ARG_WITH([skey],
1d31ef
 	]
1d31ef
 )
1d31ef
 
1d31ef
+# Check whether user wants TCP wrappers support
1d31ef
+TCPW_MSG="no"
1d31ef
+AC_ARG_WITH([tcp-wrappers],
1d31ef
+	[  --with-tcp-wrappers[[=PATH]] Enable tcpwrappers support (optionally in PATH)],
1d31ef
+	[
1d31ef
+		if test "x$withval" != "xno" ; then
1d31ef
+			saved_LIBS="$LIBS"
1d31ef
+			saved_LDFLAGS="$LDFLAGS"
1d31ef
+			saved_CPPFLAGS="$CPPFLAGS"
1d31ef
+			if test -n "${withval}" && \
1d31ef
+			    test "x${withval}" != "xyes"; then
1d31ef
+				if test -d "${withval}/lib"; then
1d31ef
+					if test -n "${need_dash_r}"; then
1d31ef
+						LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
1d31ef
+					else
1d31ef
+						LDFLAGS="-L${withval}/lib ${LDFLAGS}"
1d31ef
+					fi
1d31ef
+				else
1d31ef
+					if test -n "${need_dash_r}"; then
1d31ef
+						LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
1d31ef
+					else
1d31ef
+						LDFLAGS="-L${withval} ${LDFLAGS}"
1d31ef
+					fi
1d31ef
+				fi
1d31ef
+				if test -d "${withval}/include"; then
1d31ef
+					CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
1d31ef
+				else
1d31ef
+					CPPFLAGS="-I${withval} ${CPPFLAGS}"
1d31ef
+				fi
1d31ef
+			fi
1d31ef
+			LIBS="-lwrap $LIBS"
1d31ef
+			AC_MSG_CHECKING([for libwrap])
1d31ef
+			AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1d31ef
+#include <sys/types.h>
1d31ef
+#include <sys/socket.h>
1d31ef
+#include <netinet/in.h>
1d31ef
+#include <tcpd.h>
1d31ef
+int deny_severity = 0, allow_severity = 0;
1d31ef
+				]], [[
1d31ef
+	hosts_access(0);
1d31ef
+				]])], [
1d31ef
+					AC_MSG_RESULT([yes])
1d31ef
+					AC_DEFINE([LIBWRAP], [1],
1d31ef
+						[Define if you want
1d31ef
+						TCP Wrappers support])
1d31ef
+					SSHDLIBS="$SSHDLIBS -lwrap"
1d31ef
+					TCPW_MSG="yes"
1d31ef
+				], [
1d31ef
+					AC_MSG_ERROR([*** libwrap missing])
1d31ef
+				
1d31ef
+			])
1d31ef
+			LIBS="$saved_LIBS"
1d31ef
+		fi
1d31ef
+	]
1d31ef
+)
1d31ef
+
1d31ef
 # Check whether user wants to use ldns
1d31ef
 LDNS_MSG="no"
1d31ef
 AC_ARG_WITH(ldns,
1d31ef
@@ -5214,6 +5270,7 @@ echo "                 KerberosV support
1d31ef
 echo "                   SELinux support: $SELINUX_MSG"
1d31ef
 echo "                 Smartcard support: $SCARD_MSG"
1d31ef
 echo "                     S/KEY support: $SKEY_MSG"
1d31ef
+echo "              TCP Wrappers support: $TCPW_MSG"
1d31ef
 echo "              MD5 password support: $MD5_MSG"
1d31ef
 echo "                   libedit support: $LIBEDIT_MSG"
1d31ef
 echo "  Solaris process contract support: $SPC_MSG"
1d31ef
diff -up openssh-7.4p1/sshd.8.tcp_wrappers openssh-7.4p1/sshd.8
1d31ef
--- openssh-7.4p1/sshd.8.tcp_wrappers	2016-12-23 15:36:38.759411194 +0100
1d31ef
+++ openssh-7.4p1/sshd.8	2016-12-23 15:36:38.778411197 +0100
1d31ef
@@ -836,6 +836,12 @@ the user's home directory becomes access
1d31ef
 This file should be writable only by the user, and need not be
1d31ef
 readable by anyone else.
1d31ef
 .Pp
1d31ef
+.It Pa /etc/hosts.allow
1d31ef
+.It Pa /etc/hosts.deny
1d31ef
+Access controls that should be enforced by tcp-wrappers are defined here.
1d31ef
+Further details are described in
1d31ef
+.Xr hosts_access 5 .
1d31ef
+.Pp
1d31ef
 .It Pa /etc/hosts.equiv
1d31ef
 This file is for host-based authentication (see
1d31ef
 .Xr ssh 1 ) .
1d31ef
@@ -960,6 +966,7 @@ IPv6 address can be used everywhere wher
1d31ef
 .Xr ssh-keygen 1 ,
1d31ef
 .Xr ssh-keyscan 1 ,
1d31ef
 .Xr chroot 2 ,
1d31ef
+.Xr hosts_access 5 ,
1d31ef
 .Xr login.conf 5 ,
1d31ef
 .Xr moduli 5 ,
1d31ef
 .Xr sshd_config 5 ,
1d31ef
diff -up openssh-7.4p1/sshd.c.tcp_wrappers openssh-7.4p1/sshd.c
1d31ef
--- openssh-7.4p1/sshd.c.tcp_wrappers	2016-12-23 15:36:38.772411196 +0100
1d31ef
+++ openssh-7.4p1/sshd.c	2016-12-23 15:37:15.032417028 +0100
1d31ef
@@ -123,6 +123,13 @@
1d31ef
 #include "version.h"
1d31ef
 #include "ssherr.h"
1d31ef
 
1d31ef
+#ifdef LIBWRAP
1d31ef
+#include <tcpd.h>
1d31ef
+#include <syslog.h>
1d31ef
+int allow_severity;
1d31ef
+int deny_severity;
1d31ef
+#endif /* LIBWRAP */
1d31ef
+
1d31ef
 /* Re-exec fds */
1d31ef
 #define REEXEC_DEVCRYPTO_RESERVED_FD	(STDERR_FILENO + 1)
1d31ef
 #define REEXEC_STARTUP_PIPE_FD		(STDERR_FILENO + 2)
1d31ef
@@ -2012,6 +2019,24 @@ main(int ac, char **av)
1d31ef
 #ifdef SSH_AUDIT_EVENTS
1d31ef
 	audit_connection_from(remote_ip, remote_port);
1d31ef
 #endif
1d31ef
+#ifdef LIBWRAP
1d31ef
+	allow_severity = options.log_facility|LOG_INFO;
1d31ef
+	deny_severity = options.log_facility|LOG_WARNING;
1d31ef
+	/* Check whether logins are denied from this host. */
1d31ef
+	if (packet_connection_is_on_socket()) {
1d31ef
+		struct request_info req;
1d31ef
+
1d31ef
+		request_init(&req, RQ_DAEMON, __progname, RQ_FILE, sock_in, 0);
1d31ef
+		fromhost(&req;;
1d31ef
+
1d31ef
+		if (!hosts_access(&req)) {
1d31ef
+			debug("Connection refused by tcp wrapper");
1d31ef
+			refuse(&req;;
1d31ef
+			/* NOTREACHED */
1d31ef
+			fatal("libwrap refuse returns");
1d31ef
+		}
1d31ef
+	}
1d31ef
+#endif /* LIBWRAP */
1d31ef
 
1d31ef
 	/* Log the connection. */
1d31ef
 	laddr = get_local_ipaddr(sock_in);