- Integration of large HPUX patch from Andre Lucas
   <andre.lucas@dial.pipex.com>. Integrating it had a few other
   benefits:
   - Ability to disable shadow passwords at configure time
   - Ability to disable lastlog support at configure time
   - Support for IP address in $DISPLAY
diff --git a/configure.in b/configure.in
index 86d6a32..b5ffee7 100644
--- a/configure.in
+++ b/configure.in
@@ -1,6 +1,7 @@
 AC_INIT(ssh.c)
 
 AC_CONFIG_HEADER(config.h)
+AC_CANONICAL_HOST
 
 dnl Checks for programs.
 AC_PROG_CC
@@ -9,10 +10,35 @@
 AC_PROG_INSTALL
 AC_CHECK_PROG(AR, ar, ar)
 
+dnl Check for the path to xauth
+AC_PATH_PROG(xauth_path, xauth)
+AC_DEFINE_UNQUOTED(XAUTH_PATH, "$xauth_path")
+
 dnl Checks for compiler characteristics
 if test "$GCC" = "yes"; then CFLAGS="$CFLAGS -Wall"; fi
+
 AC_C_INLINE
 
+dnl Check for some target-specific stuff
+case "$host" in
+*-*-hpux10*)
+	if test -z "$GCC"; then
+		CFLAGS="$CFLAGS -Aa"
+	fi
+	CFLAGS="$CFLAGS -D_HPUX_SOURCE"
+	AC_DEFINE(IPADDR_IN_DISPLAY)
+	AC_MSG_CHECKING(for HPUX trusted system password database)
+	if test -f /tcb/files/auth/system/default; then
+		AC_MSG_RESULT(yes)
+		AC_DEFINE(HAVE_HPUX_TRUSTED_SYSTEM_PW)
+		LIBS="$LIBS -lsec"
+	else
+		AC_MSG_RESULT(no)
+		AC_DEFINE(DISABLE_SHADOW)
+	fi
+	;;
+esac
+
 dnl Check for OpenSSL/SSLeay directories.
 AC_MSG_CHECKING([for OpenSSL/SSLeay directory])
 for ssldir in /usr /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local $prefix /usr/pkg ; do
@@ -59,10 +85,10 @@
 AC_CHECK_LIB(pam, pam_authenticate, , )
 
 dnl Checks for header files.
-AC_CHECK_HEADERS(endian.h lastlog.h login.h maillock.h netgroup.h paths.h poll.h pty.h shadow.h util.h utmp.h utmpx.h sys/poll.h sys/select.h sys/stropts.h sys/time.h)
+AC_CHECK_HEADERS(endian.h lastlog.h login.h maillock.h netgroup.h paths.h poll.h pty.h shadow_h util.h utmp.h utmpx.h sys/bsdtty.h sys/poll.h sys/select.h sys/stropts.h sys/time.h)
 
 dnl Checks for library functions.
-AC_CHECK_FUNCS(arc4random mkdtemp openpty _getpty setenv setlogin setproctitle snprintf strlcat strlcpy vsnprintf)
+AC_CHECK_FUNCS(arc4random mkdtemp openpty _getpty setenv seteuid setlogin setproctitle setreuid snprintf strlcat strlcpy vsnprintf)
 
 AC_CHECK_FUNC(login, 
 	[AC_DEFINE(HAVE_LOGIN)],
@@ -209,27 +235,46 @@
 )
 
 dnl Look for lastlog location
-AC_MSG_CHECKING([location of lastlog file])
-for lastlog in /var/log/lastlog /var/adm/lastlog /etc/security/lastlog ; do
-	if test -f $lastlog ; then
-		gotlastlog="file"
-		break
-	fi
-	if test -d $lastlog ; then
-		gotlastlog="dir"
-		break
-	fi
-done
-if test -z "$gotlastlog" ; then
-	AC_MSG_ERROR([*** Cannot find lastlog ***])
-else
-	if test "x$gotlastlog" = "xdir" ; then
-		AC_DEFINE(LASTLOG_IS_DIR)
-		AC_MSG_ERROR([*** Directory-based lastlogs are not yet supported ***])
-	fi
-	AC_MSG_RESULT($lastlog)
-	AC_DEFINE_UNQUOTED(LASTLOG_LOCATION, "$lastlog")
-fi	
+AC_ARG_WITH(lastlog,
+	[  --with-lastlog          Location of lastlog file],
+	[
+		if test "x$withval" = "xno" ; then
+			AC_DEFINE(DISABLE_LASTLOG)
+		else
+			AC_DEFINE_UNQUOTED(LASTLOG_LOCATION, "$withval")
+		fi
+	],
+	[
+		AC_MSG_CHECKING([location of lastlog file])
+		for lastlog in /var/log/lastlog /var/adm/lastlog /etc/security/lastlog ; do
+			if test -f $lastlog ; then
+				gotlastlog="file"
+				break
+			fi
+			if test -d $lastlog ; then
+				gotlastlog="dir"
+				break
+			fi
+		done
+		if test -z "$gotlastlog" ; then
+			AC_MSG_WARN([*** Cannot find lastlog ***])
+			nolastlog=1
+		else
+			if test "x$gotlastlog" = "xdir" ; then
+				AC_DEFINE(LASTLOG_IS_DIR)
+				AC_MSG_WARN([*** Directory-based lastlogs are not yet supported ***])
+				nolastlog=1
+			fi
+			AC_MSG_RESULT($lastlog)
+			AC_DEFINE_UNQUOTED(LASTLOG_LOCATION, "$lastlog")
+		fi	
+	]
+)
+
+if test ! -z "$nolastlog" ; then
+	AC_MSG_WARN([*** Disabling lastlog support *** ])
+	AC_DEFINE(DISABLE_LASTLOG)
+fi
 
 AC_CHECK_FILE("/dev/ptmx", AC_DEFINE_UNQUOTED(HAVE_DEV_PTMX))
 AC_CHECK_FILE("/dev/ptc", AC_DEFINE_UNQUOTED(HAVE_DEV_PTS_AND_PTC))
@@ -293,11 +338,37 @@
 dnl Check whether to enable utmpx support
 AC_ARG_WITH(utmpx,
 	[  --with-utmpx            Enable utmpx support],
-	[AC_DEFINE(USE_UTMPX)]
+	[
+		if test "x$withval" != "xno" ; then
+			AC_DEFINE(USE_UTMPX)
+		fi
+	]
 )
 
-dnl Check for the path to xauth
-AC_PATH_PROG(xauth_path, xauth)
-AC_DEFINE_UNQUOTED(XAUTH_PATH, "$xauth_path")
+dnl Whether to disable shadow password support
+AC_ARG_WITH(shadow,
+	[  --without-shadow        Disable shadow password support],
+	[
+		if test "x$withval" = "xno" ; then	
+			AC_DEFINE(DISABLE_SHADOW)
+		fi
+	]
+)
+
+dnl Use ip address instead of hostname in $DISPLAY
+AC_ARG_WITH(ipaddr-display,
+	[  --with-ipaddr-display   Use ip address instead of hostname in \$DISPLAY],
+	[
+		if test "x$withval" = "xno" ; then	
+			AC_DEFINE(IPADDR_IN_DISPLAY)
+		fi
+	]
+)
+
+dnl Check for mail directory (last resort if we cannot get it from headers)
+if test ! -z "$MAIL" ; then
+	maildir=`dirname $MAIL`
+	AC_DEFINE_UNQUOTED(MAIL_DIRECTORY, "$maildir")
+fi
 
 AC_OUTPUT(Makefile)