Skip to content

Commit

Permalink
Restore tcpwrappers libwrap support
Browse files Browse the repository at this point in the history
  • Loading branch information
citrus-it committed Jul 2, 2024
1 parent 984ab15 commit b5845c9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
57 changes: 57 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,62 @@ else
AC_MSG_RESULT([no])
fi

# Check whether user wants TCP wrappers support
TCPW_MSG="no"
AC_ARG_WITH([tcp-wrappers],
[ --with-tcp-wrappers[[=PATH]] Enable tcpwrappers support (optionally in PATH)],
[
if test "x$withval" != "xno" ; then
saved_LIBS="$LIBS"
saved_LDFLAGS="$LDFLAGS"
saved_CPPFLAGS="$CPPFLAGS"
if test -n "${withval}" && \
test "x${withval}" != "xyes"; then
if test -d "${withval}/lib"; then
if test -n "${need_dash_r}"; then
LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
else
LDFLAGS="-L${withval}/lib ${LDFLAGS}"
fi
else
if test -n "${need_dash_r}"; then
LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
else
LDFLAGS="-L${withval} ${LDFLAGS}"
fi
fi
if test -d "${withval}/include"; then
CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
else
CPPFLAGS="-I${withval} ${CPPFLAGS}"
fi
fi
LIBS="-lwrap $LIBS"
AC_MSG_CHECKING([for libwrap])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <tcpd.h>
int deny_severity = 0, allow_severity = 0;
]], [[
hosts_access(0);
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([LIBWRAP], [1],
[Define if you want
TCP Wrappers support])
SSHDLIBS="$SSHDLIBS -lwrap"
TCPW_MSG="yes"
], [
AC_MSG_ERROR([*** libwrap missing])
])
LIBS="$saved_LIBS"
fi
]
)

# Check whether user wants to use ldns
LDNS_MSG="no"
AC_ARG_WITH(ldns,
Expand Down Expand Up @@ -5714,6 +5770,7 @@ echo " PAM support: $PAM_MSG"
echo " OSF SIA support: $SIA_MSG"
echo " KerberosV support: $KRB5_MSG"
echo " SELinux support: $SELINUX_MSG"
echo " TCP Wrappers support: $TCPW_MSG"
echo " libedit support: $LIBEDIT_MSG"
echo " libldns support: $LDNS_MSG"
echo " Solaris process contract support: $SPC_MSG"
Expand Down
24 changes: 24 additions & 0 deletions sshd-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
#include <prot.h>
#endif

#ifdef LIBWRAP
#include <tcpd.h>
#include <syslog.h>
#endif /* LIBWRAP */

#include "xmalloc.h"
#include "ssh.h"
#include "ssh2.h"
Expand Down Expand Up @@ -1269,6 +1274,25 @@ main(int ac, char **av)
audit_connection_from(ssh, remote_ip, remote_port);
#endif

#ifdef LIBWRAP
int allow_severity = options.log_facility|LOG_INFO;
int deny_severity = options.log_facility|LOG_WARNING;
/* Check whether logins are denied from this host. */
if (ssh_packet_connection_is_on_socket(ssh)) {
struct request_info req;

request_init(&req, RQ_DAEMON, __progname, RQ_FILE, sock_in, 0);
fromhost(&req);

if (!hosts_access(&req)) {
debug("Connection refused by tcp wrapper");
refuse(&req);
/* NOTREACHED */
fatal("libwrap refuse returns");
}
}
#endif /* LIBWRAP */

rdomain = ssh_packet_rdomain_in(ssh);

/* Log the connection. */
Expand Down
7 changes: 7 additions & 0 deletions sshd.8
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,12 @@ the user's home directory becomes accessible.
This file should be writable only by the user, and need not be
readable by anyone else.
.Pp
.It Pa /etc/hosts.allow
.It Pa /etc/hosts.deny
Access controls that should be enforced by tcp-wrappers are defined here.
Further details are described in
.Xr hosts_access 5 .
.Pp
.It Pa /etc/hosts.equiv
This file is for host-based authentication (see
.Xr ssh 1 ) .
Expand Down Expand Up @@ -1048,6 +1054,7 @@ Each SSHv2 userauth type has its own PAM service name:
.Xr ssh-keygen 1 ,
.Xr ssh-keyscan 1 ,
.Xr chroot 2 ,
.Xr hosts_access 5 ,
.Xr login.conf 5 ,
.Xr moduli 5 ,
.Xr sshd_config 5 ,
Expand Down

0 comments on commit b5845c9

Please sign in to comment.