--- src/ptytty.C.orig	2007-11-07 16:54:35.000000000 +0100
+++ src/ptytty.C	2007-11-07 16:56:13.000000000 +0100
@@ -353,6 +353,9 @@
 #if UTMP_SUPPORT
   logout ();
 #endif
+#ifdef HAVE_UTEMPTER
+  logout ();
+#endif 
   put ();
 }
 
--- src/ptytty.h.orig	2007-11-07 16:54:30.000000000 +0100
+++ src/ptytty.h	2007-11-07 16:57:01.000000000 +0100
@@ -86,6 +86,11 @@
 
   void logout ();
 #endif
+
+#ifdef HAVE_UTEMPTER
+  void logout ();
+#endif
+
 };
 
 #endif
--- configure.ac.orig	2007-11-07 17:10:04.000000000 +0100
+++ configure.ac	2007-11-07 17:12:02.000000000 +0100
@@ -152,6 +152,7 @@
        support_scroll_plain=no
        support_utmp=no
        support_wtmp=no
+       support_utempter=no
        support_xim=no
        support_afterimage=no
        support_afterstep=no
@@ -182,6 +183,7 @@
        support_utmp=yes
        support_wtmp=yes
        support_xim=yes
+       support_utempter=no
        support_afterimage=yes
        support_afterstep=yes
        support_xft=yes
@@ -634,7 +636,36 @@
 	on_exit \
 )
 
-UTMP_CHECK
+AC_ARG_ENABLE(utempter,
+  [  --enable-utempter       enable utempter support (conflicts --enable utmp)],
+  [if test x$enableval = xyes -o x$enableval = xno; then
+    support_utempter=$enableval
+  fi])
+
+
+if test x$support_utempter = xyes; then
+  AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
+  if test $PKG_CONFIG != no && $PKG_CONFIG --exists utempter; then
+    LIBS="$LIBS `$PKG_CONFIG utempter --libs`"
+    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG utempter --cflags`"
+  else
+    LIBS="$LIBS -lutempter"
+  fi
+
+
+  AC_CHECK_HEADERS(utempter.h,,[support_utempter=no])
+  AC_CHECK_LIB(utempter,utempter_add_record,,[support_utempter=no])
+
+  if test x$support_utempter = xyes; then
+    AC_DEFINE(HAVE_UTEMPTER, 1, Define to enable utempter support)
+  fi
+  dnl# wtmp and lastlog need utmp so this check should be sane...
+  if test x$support_utmp = yes; then
+    AC_ERROR([You can only specify either utmp or utempter support.])
+  fi
+else
+  UTMP_CHECK
+fi
 
 dnl# --------------------------------------------------------------------------
 
--- src/logging.C.orig	2007-11-08 00:23:39.000000000 +0100
+++ src/logging.C	2007-11-08 00:24:34.000000000 +0100
@@ -461,9 +461,28 @@
 #endif				/* LASTLOG_SUPPORT */
 
 #else
+
+#ifdef HAVE_UTEMPTER
+#include <utempter.h>
 void
 ptytty_unix::login (int cmd_pid, bool login_shell, const char *hostname)
 {
+    if(login_shell)
+    {
+	utempter_add_record (pty, hostname);
+    }
+}
+
+void
+ptytty_unix::logout ()
+{
+    utempter_remove_added_record ();
 }
+#else
+void
+ptytty_unix::login (int cmd_pid, bool login_shell, const char *hostname)
+{
+}
+#endif
 #endif
 
