bmh10 / rpms / openssh

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