commit-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-140-geb139


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-140-geb139e0
Date: Wed, 01 Aug 2012 13:51:23 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  eb139e0534d61c51226ddd6c436c655f94532b1e (commit)
       via  5d9c59cbcd0c9967986e1a14907ea1d87e8a5d9c (commit)
      from  4689d41a2a7b7f60aec12e60189ae467169c2bc3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=eb139e0534d61c51226ddd6c436c655f94532b1e


commit eb139e0534d61c51226ddd6c436c655f94532b1e
Author: Mats Erik Andersson <address@hidden>
Date:   Wed Aug 1 15:16:47 2012 +0200

    Reworked support for utmpx/utmp.

diff --git a/ChangeLog b/ChangeLog
index 6a409fa..85c70d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,63 @@
+2012-08-01  Mats Erik Andersson  <address@hidden>
+
+       Better adaptions to different UTMP implementations.
+       FreeBSD 9.0 has left most traditions behind.
+
+       * configure.ac: Check for login, loginx, logoutx, logwtmp,
+       and logwtmpx conditioned on libutil.  Ensure `LIBUTIL=-lutil'
+       in cases where `$ac_cv_func_login_tty = yes' or
+       `$ac_cv_have_decl_openpty = yes'.  Check for more fields in
+       `struct utmp': ut_line, ut_session, ut_time, ut_addr_v6,
+       and ut_name.  Check for `struct lastlogx' and field ll_ss.
+       Add checks of `struct utmpx' for fields ut_user, ut_name,
+       ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_tv, ut_session,
+       ut_syslen, ut_host, ut_ss, ut_addr_v6.  Check for pututline
+       and pututxline.
+       (UTMPX): Removed macro.
+
+       * libinetutils/libinetutils.h (utmp_init): Update.
+       * libinetutils/cleansess.c [HAVE_LOGOUT && HAVE_LOGWTMP]:
+       Make the source build conditionally.
+       * libinetutils/logwtmp.c: Prefer utmpx code if available.
+       Conditionally use fields in `struct utmpx' or `struct utmp'.
+       * libinetutils/logwtmpko.c (logwtmp)
+       [HAVE_UPDWTMPX && !HAVE_LOGWTMP]: New condition on build,
+       and migration to `struct utmpx'.
+       * libinetutils/utmp_init.c: Add parameter `char *host'.
+       Guard structure fields with conditionals.  Distinguish
+       access methods on HAVE_PUTUTXLINE, HAVE_LOGINX, and
+       HAVE_UPDWTMPX, HAVE_LOGWTMPX.  Similarly, test
+       HAVE_PUTUTLINE, HAVE_LOGIN, HAVE_UPDWTMP, and HAVE_LOGWTMP.
+       New calls to setutxent() or setutent().
+       * libinetutils/utmp_logout.c: Essentially likewise.  Erase the
+       fields ut_exit, ut_user, ut_name, and ut_host.
+       [HAVE_LOGOUTX]: Protect call to logoutx()/logwtmpx().
+       [HAVE_LOGOUT]: Likewise for logout()/logwtmp().
+
+       * libls/print.c: Do not include <utmp.h>.
+
+       * src/rlogind.c: Remove conditional on UTMPX and local
+       prototypes for utmp_ptsid() and utmp_init().  Always use
+       setup_utmp()
+       (setup_utmp): New argument `host'.
+       [!HAVE_LOGOUT && !HAVE_LOGWTMP]: Call utmp_logout().
+
+       * src/uucpd.c [HAVE_UTMPX_H]: Include <utmpx.h>.
+       (dologout) [HAVE_LOGWTMPX]: Call logwtmpx().
+       [HAVE_LOGWTMP && !HAVE_LOGWTMP]: Call logwtmp().
+       [HAVE_PUTUTXLINE && !HAVE_LOGWTMPX && !HAVE_LOGWTMP]:
+       Manual setup for recent FreeBSD.
+       (dologin): Likewise.
+
+       * telnetd/pty.c: Always use setup_utmp().
+       (setup_utmp): New argument `host'.
+
+       FreeBSD 9.0 uses new paths.
+
+       * paths (PATH_UTMPX): Add `/var/run/utx.active'.
+       (PATH_WTMPX): Add `/var/run/utx.log'.
+       (PATH_LASTLOG): Add `/var/run/utx.lastlogin'.
+
 2012-07-29  Mats Erik Andersson  <address@hidden>
 
        Out-of-tree build with libshishi.
diff --git a/configure.ac b/configure.ac
index ca9f267..0c41949 100644
--- a/configure.ac
+++ b/configure.ac
@@ -170,9 +170,25 @@ AC_SUBST(LIBCRYPT)
 # libutil is a 4.4BSD library that defines several functions handy for
 # inetutils daemons, doing such things as utmp frobbing, and pty
 # setup.
+AC_CHECK_LIB(util, login, LIBUTIL=-lutil)
+AC_CHECK_LIB(util, loginx, LIBUTIL=-lutil)
 AC_CHECK_LIB(util, logout, LIBUTIL=-lutil)
+AC_CHECK_LIB(util, logoutx, LIBUTIL=-lutil)
+AC_CHECK_LIB(util, logwtmp, LIBUTIL=-lutil)
+AC_CHECK_LIB(util, logwtmpx, LIBUTIL=-lutil)
 AC_SUBST(LIBUTIL)
 
+# FreeBSD 9.0 has changed access to wtmp system, abolishing
+# logout(), logwtmp(), etcetera.  We need to use LIBUTIL
+# for rpl_openpty() and forkpty() in libgnu.a.
+if test "$ac_cv_func_login_tty" = yes \
+   || test "$ac_cv_have_decl_openpty" = yes; then
+  # Make sure that linking contains `-lutil'.
+  if test -z "$LIBUTIL"; then
+    LIBUTIL=-lutil
+  fi
+fi
+
 # Check if they want support for PAM.  Certain daemons like ftpd have
 # support for it.
 
@@ -516,8 +532,8 @@ fi
 # support for it.
 
 if test "$with_wrap" = yes; then
-# See if we have libwrap.a we cannot use AC_CHECK_LIB reliably since
-# for the wrap lib you have to define some global variables
+# See if we have libwrap.a.  We cannot use AC_CHECK_LIB reliably since
+# for the wrap lib you have to define some global variables.
 #AC_CHECK_LIB(wrap, hosts_ctl, LIBWRAP=-lwrap)
   AC_CHECK_HEADERS([tcpd.h])
   AC_MSG_CHECKING(hosts_ctl in -lwrap);
@@ -603,18 +619,33 @@ AC_CHECK_TYPE(sig_atomic_t, , AC_DEFINE([sig_atomic_t], 
int, [FIXME]),
 IU_CHECK_MEMBERS([struct sockaddr_in.sin_len], , ,
     [ #include <sys/types.h>
       #include <netinet/in.h> ])
+IU_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , ,
+    [ #include <sys/types.h>
+      #include <netinet/in.h> ])
 
 if test "$ac_cv_header_utmp_h" = yes; then
   AC_CHECK_TYPES(struct lastlog, , , [#include <utmp.h>])
   IU_CHECK_MEMBERS([struct utmp.ut_type, struct utmp.ut_pid,
-                    struct utmp.ut_id, struct utmp.ut_user,
-                   struct utmp.ut_host, struct utmp.ut_tv,
-                   struct utmp.ut_exit], , ,
+                   struct utmp.ut_line, struct utmp.ut_id,
+                   struct utmp.ut_user, struct utmp.ut_host,
+                   struct utmp.ut_exit, struct utmp.ut_session,
+                   struct utmp.ut_tv, struct utmp.ut_time,
+                   struct utmp.ut_addr_v6, struct utmp.ut_name], , ,
                   [#include <sys/types.h>
                    #include <utmp.h>])
 fi
 if test "$ac_cv_header_utmpx_h" = yes; then
-  IU_CHECK_MEMBERS([struct utmpx.ut_tv], , , [#include <utmpx.h>])
+  AC_CHECK_TYPES(struct lastlogx, , , [#include <utmp.h>])
+  IU_CHECK_MEMBERS([struct lastlogx.ll_ss], , ,
+                  [#include <sys/types.h>
+                   #include <sys/utmpx.h>])
+  IU_CHECK_MEMBERS([struct utmpx.ut_user, struct utmpx.ut_name,
+                   struct utmpx.ut_id, struct utmpx.ut_line,
+                   struct utmpx.ut_pid, struct utmpx.ut_type,
+                   struct utmpx.ut_exit, struct utmpx.ut_tv,
+                   struct utmpx.ut_session, struct utmpx.ut_syslen,
+                   struct utmpx.ut_host, struct utmpx.ut_ss,
+                   struct utmpx.ut_aadr_v6], , , [#include <utmpx.h>])
 fi
 
 IU_CHECK_MEMBERS([struct ifreq.ifr_index,
@@ -663,7 +694,7 @@ AC_CHECK_FUNCS(cfsetspeed cgetent dirfd fchdir flock \
                fork fpathconf ftruncate \
                getcwd getmsg getpwuid_r getspnam \
                initgroups initsetproctitle killpg \
-               ptsname \
+               ptsname pututline pututxline \
                setegid seteuid setpgid \
                setsid setregid setreuid setresgid setresuid setutent_r \
                sigaction sigvec strchr setproctitle tcgetattr tzset utimes \
@@ -671,6 +702,13 @@ AC_CHECK_FUNCS(cfsetspeed cgetent dirfd fchdir flock \
                updwtmp updwtmpx vhangup wait3 wait4 opendir2 \
               __rcmd_errstr __check_rhosts_file )
 
+# Variant functions for user accounting.
+# These need $LIBUTIL for linking.
+_SAVE_LIBS="$LIBS"
+LIBS="$LIBS $LIBUTIL"
+AC_CHECK_FUNCS(login loginx logout logoutx logwtmp logwtmpx)
+LIBS="$_SAVE_LIBS"
+
 # Functions that we will define if necessary.
 AC_REPLACE_FUNCS(getpass getusershell memcmp memcpy memmove memset \
                 strdup poll)
@@ -869,16 +907,15 @@ AH_BOTTOM(
 
 # Ok this is the end of the rope, even autoconf can't help.  For
 # example on certain system login(1) will not work if we don't have an
-# entry in utmpx.  Also for some OS they are better handle with
+# entry in utmpx.  Also for some OS they are better handled with
 # STREAMS.
 case "$host" in
 *olaris*)
   AC_DEFINE([SOLARIS], 1, [FIXME])
-  AC_DEFINE([UTMPX], 1, [FIXME])
   AC_DEFINE([HAVE_STREAMSPTY], 1, [FIXME])
   ;;
-*irix* | *hpux* | *netbsd* | *dragonfly* )
-  AC_DEFINE([UTMPX], 1, [FIXME])
+*irix* | *hpux* )
+  # Known and needed workarounds?
   ;;
 esac
 
diff --git a/libinetutils/cleansess.c b/libinetutils/cleansess.c
index 6efff70..5fa811d 100644
--- a/libinetutils/cleansess.c
+++ b/libinetutils/cleansess.c
@@ -41,6 +41,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#if defined HAVE_LOGOUT && HAVE_LOGWTMP
+
 /* Update umtp & wtmp as necessary, and change tty & pty permissions back to
    what they should be.  */
 void
@@ -48,11 +50,11 @@ cleanup_session (char *tty, int pty_fd)
 {
   char *line;
 
-#ifdef PATH_TTY_PFX
+# ifdef PATH_TTY_PFX
   if (strncmp (tty, PATH_TTY_PFX, sizeof PATH_TTY_PFX - 1) == 0)
     line = tty + sizeof PATH_TTY_PFX - 1;
   else
-#endif
+# endif /* PATH_TTY_PFX */
     line = tty;
 
   if (logout (line))
@@ -63,3 +65,4 @@ cleanup_session (char *tty, int pty_fd)
   fchmod (pty_fd, 0666);
   fchown (pty_fd, 0, 0);
 }
+#endif /* HAVE_LOGOUT && HAVE_LOGWTMP */
diff --git a/libinetutils/libinetutils.h b/libinetutils/libinetutils.h
index 7329eba..9286383 100644
--- a/libinetutils/libinetutils.h
+++ b/libinetutils/libinetutils.h
@@ -23,7 +23,7 @@
 
 #include "argp-version-etc.h"
 
-void utmp_init (char *line, char *user, char *id);
+void utmp_init (char *line, char *user, char *id, char *host);
 char *utmp_ptsid (char *line, char *tag);
 void utmp_logout (char *line);
 char *localhost (void);
diff --git a/libinetutils/logwtmp.c b/libinetutils/logwtmp.c
index 84dc3dc..4f676f9 100644
--- a/libinetutils/logwtmp.c
+++ b/libinetutils/logwtmp.c
@@ -34,13 +34,14 @@
 #include <sys/stat.h>
 #include <sys/file.h>
 #include <errno.h>
-#ifdef HAVE_UTMP_H
-# include <utmp.h>
-#else
-# ifdef  HAVE_UTMPX_H
-#  include <utmpx.h>
-#  define utmp utmpx           /* make utmpx look more like utmp */
+#ifdef HAVE_UTMPX_H
+# ifndef __USE_GNU
+#  define __USE_GNU 1
 # endif
+# include <utmpx.h>
+#elif defined HAVE_UTMP_H
+# include <utmp.h>
+# define PATH_WTMPX PATH_WTMP  /* Simplifies file referencing.  */
 #endif
 #include <string.h>
 
@@ -48,16 +49,21 @@
 extern int errno;
 #endif
 
+#ifdef HAVE_UTMPX_H
+static void
+_logwtmp (struct utmpx *ut)
+#else /* !HAVE_UTMPX_H */
 static void
 _logwtmp (struct utmp *ut)
+#endif /* !HAVE_UTMP_H */
 {
 #ifdef KEEP_OPEN
   static int fd = -1;
 
   if (fd < 0)
-    fd = open (PATH_WTMP, O_WRONLY | O_APPEND, 0);
+    fd = open (PATH_WTMPX, O_WRONLY | O_APPEND, 0);
 #else
-  int fd = open (PATH_WTMP, O_WRONLY | O_APPEND, 0);
+  int fd = open (PATH_WTMPX, O_WRONLY | O_APPEND, 0);
 #endif
 
   if (fd >= 0)
@@ -97,23 +103,43 @@ logwtmp_keep_open (char *line, char *name, char *host)
 logwtmp (char *line, char *name, char *host)
 #endif
 {
+#ifdef HAVE_UTMPX_H
+  struct utmpx ut;
+  struct timeval tv;
+#else /* !HAVE_UTMPX_H */
   struct utmp ut;
-#ifdef HAVE_STRUCT_UTMP_UT_TV
+# ifdef HAVE_STRUCT_UTMP_UT_TV
   struct timeval tv;
+# endif
 #endif
 
   /* Set information in new entry.  */
   memset (&ut, 0, sizeof (ut));
-#ifdef HAVE_STRUCT_UTMP_UT_TYPE
-  ut.ut_type = USER_PROCESS;
-#endif
+#if defined HAVE_STRUCT_UTMP_UT_TYPE || defined HAVE_STRUCT_UTMPX_UT_TYPE
+  if (name && *name)
+    ut.ut_type = USER_PROCESS;
+  else
+    ut.ut_type = DEAD_PROCESS;
+#endif /* UT_TYPE */
+#if defined HAVE_STRUCT_UTMP_UT_PID || defined HAVE_STRUCT_UTMPX_UT_PID
+  ut.ut_pid = getpid ();
+#endif /* UT_PID */
+
   strncpy (ut.ut_line, line, sizeof ut.ut_line);
+#if defined HAVE_STRUCT_UTMP_UT_USER || defined HAVE_STRUCT_UTMPX_UT_USER
+  strncpy (ut.ut_user, name, sizeof ut.ut_user);
+#elif defined HAVE_STRUCT_UTMP_UT_NAME || defined HAVE_STRUCT_UTMPX_UT_NAME
   strncpy (ut.ut_name, name, sizeof ut.ut_name);
-#ifdef HAVE_STRUCT_UTMP_UT_HOST
-  strncpy (ut.ut_host, host, sizeof ut.ut_host);
 #endif
 
-#ifdef HAVE_STRUCT_UTMP_UT_TV
+#if defined HAVE_STRUCT_UTMP_UT_HOST || defined HAVE_STRUCT_UTMPX_UT_HOST
+  strncpy (ut.ut_host, host, sizeof ut.ut_host);
+# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN    /* Only utmpx.  */
+  ut.ut_syslen = strlen (host) + 1;    /* Including NUL.  */
+# endif /* UT_SYSLEN */
+#endif /* UT_HOST */
+
+#if defined HAVE_STRUCT_UTMP_UT_TV || defined HAVE_STRUCT_UTMPX_UT_TV
   gettimeofday (&tv, NULL);
   ut.ut_tv.tv_sec = tv.tv_sec;
   ut.ut_tv.tv_usec = tv.tv_usec;
diff --git a/libinetutils/logwtmpko.c b/libinetutils/logwtmpko.c
index 2209b15..ec4135a 100644
--- a/libinetutils/logwtmpko.c
+++ b/libinetutils/logwtmpko.c
@@ -20,7 +20,7 @@
 
 #include <config.h>
 
-#if HAVE_UTMPX_H && defined SOLARIS
+#if defined HAVE_UPDWTMPX && !defined HAVE_LOGWTMP
 # include <utmpx.h>    /* updwtmp() */
 #endif
 
@@ -30,33 +30,41 @@
 /* Solaris does not provide logwtmp(3c).
  * It is needed in addition to logwtmp_keep_open().
  */
-#if HAVE_UPDWTMP && defined SOLARIS
+#if defined HAVE_UPDWTMPX && !defined HAVE_LOGWTMP
 void
 logwtmp (char *line, char *name, char *host)
 {
-  struct utmp ut;
-#ifdef HAVE_STRUCT_UTMP_UT_TV
+  struct utmpx ut;
   struct timeval tv;
-#endif
 
   memset (&ut, 0, sizeof (ut));
-#ifdef HAVE_STRUCT_UTMP_UT_TYPE
-  ut.ut_type = USER_PROCESS;
-#endif
+#ifdef HAVE_STRUCT_UTMPX_UT_TYPE
+  if (name && *name)
+    ut.ut_type = USER_PROCESS;
+  else
+    ut.ut_type = DEAD_PROCESS;
+#endif /* UT_TYPE */
+
   strncpy (ut.ut_line, line, sizeof ut.ut_line);
+#ifdef HAVE_STRUCT_UTMPX_UT_USER
+  strncpy (ut.ut_user, name, sizeof ut.ut_user);
+#elif defined HAVE_STRUCT_UTMPX_UT_NAME
   strncpy (ut.ut_name, name, sizeof ut.ut_name);
-#ifdef HAVE_STRUCT_UTMP_UT_HOST
+#endif
+#ifdef HAVE_STRUCT_UTMPX_UT_HOST
   strncpy (ut.ut_host, host, sizeof ut.ut_host);
+# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
+  ut.ut_syslen = strlen (host) + 1;    /* Including NUL.  */
+# endif /* UT_SYSLEN */
+#endif
+#ifdef HAVE_STRUCT_UTMPX_UT_PID
+  ut.ut_pid = getpid ();
 #endif
 
-# ifdef HAVE_STRUCT_UTMP_UT_TV
   gettimeofday (&tv, NULL);
   ut.ut_tv.tv_sec = tv.tv_sec;
   ut.ut_tv.tv_usec = tv.tv_usec;
-# else
-  time (&ut.ut_time);
-# endif
 
-  updwtmp (PATH_WTMP, &ut);
+  updwtmpx (PATH_WTMPX, &ut);
 }
-#endif /* HAVE_UPDWTMP && defined SOLARIS */
+#endif /* HAVE_UPDWTMPX && !HAVE_LOGWTMP */
diff --git a/libinetutils/utmp_init.c b/libinetutils/utmp_init.c
index ce30c5f..a15781c 100644
--- a/libinetutils/utmp_init.c
+++ b/libinetutils/utmp_init.c
@@ -38,7 +38,8 @@
  */
 
 /* Written by Wietse Venema.  With port to GNU Inetutils done by Alain
-   Magloire.  */
+   Magloire.  Reorganized to cope with full variation between utmpx
+   and utmp, with different API sets, by Mats Erik Andersson.  */
 
 #include <config.h>
 
@@ -48,10 +49,10 @@
 #include <time.h>
 #ifdef HAVE_UTMPX_H
 # ifndef __USE_GNU
-#  define __USE_GNU
+#  define __USE_GNU 1
 # endif
 # include <utmpx.h>
-#else
+#else /* !HAVE_UTMPX_H */
 # if HAVE_UTIL_H
 #  include <util.h>
 # endif
@@ -63,19 +64,20 @@
 /* utmp_init - update utmp and wtmp before login */
 
 void
-utmp_init (char *line, char *user, char *id)
+utmp_init (char *line, char *user, char *id, char *host)
 {
 #ifdef HAVE_UTMPX_H
   struct utmpx utx;
-#else
+  struct timeval tv;
+#else /* !HAVE_UTMPX_H */
   struct utmp utx;
-#endif
-#if defined HAVE_STRUCT_UTMPX_UT_TV
+# if defined HAVE_STRUCT_UTMP_UT_TV
   struct timeval tv;
+# endif
 #endif
 
   memset ((char *) &utx, 0, sizeof (utx));
-#if defined HAVE_STRUCT_UTMP_UT_ID
+#if defined HAVE_STRUCT_UTMP_UT_ID || defined HAVE_STRUCT_UTMPX_UT_ID
   strncpy (utx.ut_id, id, sizeof (utx.ut_id));
 #endif
 #if defined HAVE_STRUCT_UTMP_UT_USER || defined HAVE_STRUCT_UTMPX_UT_USER
@@ -83,40 +85,72 @@ utmp_init (char *line, char *user, char *id)
 #elif defined HAVE_STRUCT_UTMP_UT_NAME || defined HAVE_STRUCT_UTMPX_UT_NAME
   strncpy (utx.ut_name, user, sizeof (utx.ut_name));
 #endif
-#if defined HAVE_STRUCT_UTMP_UT_HOST
-  strncpy (utx.ut_host, user, sizeof (utx.ut_host));
-#endif
+#if defined HAVE_STRUCT_UTMP_UT_HOST || defined HAVE_STRUCT_UTMPX_UT_HOST
+  strncpy (utx.ut_host, host, sizeof (utx.ut_host));
+# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN    /* Only utmpx.  */
+  utx.ut_syslen = strlen (host) + 1;
+# endif
+#endif /* UT_HOST */
+#if defined HAVE_STRUCT_UTMP_UT_LINE || defined HAVE_STRUCT_UTMPX_UT_LINE
   strncpy (utx.ut_line, line, sizeof (utx.ut_line));
-#if defined HAVE_STRUCT_UTMP_UT_PID
+#endif
+
+#if defined HAVE_STRUCT_UTMP_UT_PID || defined HAVE_STRUCT_UTMPX_UT_PID
   utx.ut_pid = getpid ();
 #endif
-#if defined HAVE_STRUCT_UTMP_UT_TYPE
+#if defined HAVE_STRUCT_UTMP_UT_TYPE || defined HAVE_STRUCT_UTMPX_UT_TYPE
   utx.ut_type = LOGIN_PROCESS;
 #endif
-#if defined HAVE_STRUCT_UTMPX_UT_TV
+#if defined HAVE_STRUCT_UTMP_UT_TV || defined HAVE_STRUCT_UTMPX_UT_TV
   gettimeofday (&tv, 0);
   utx.ut_tv.tv_sec = tv.tv_sec;
   utx.ut_tv.tv_usec = tv.tv_usec;
 #else
   time (&(utx.ut_time));
 #endif
+
+/* Prefer utmpx over utmp, and attempt to
+ * use pututxline/pututline for writing the
+ * initial entry.  Then apply whatever
+ * wtmp updating that happens to be available.
+ *
+ * That failing, fall back to loginx/login.
+ * This is made in order than we are granted
+ * LOGIN_PROCESS type and stay unbound by
+ * any tty sensing of stdin, stdout, or stderr,
+ * like GNU libc would do in login().
+ */
 #ifdef HAVE_UTMPX_H
+# ifdef HAVE_PUTUTXLINE
+  setutxent ();
   pututxline (&utx);
-# ifdef HAVE_UPDWTMPX
+  /* Some systems perform wtmp updating
+   * already in calling pututxline().
+   */
+#  ifdef HAVE_UPDWTMPX
   updwtmpx (PATH_WTMPX, &utx);
-# endif
+#  elif defined HAVE_LOGWTMPX
+  logwtmpx (line, user, id, 0, LOGIN_PROCESS);
+#  endif /* wtmp updating */
   endutxent ();
-#elif HAVE_DECL_GETUTENT
+# elif defined HAVE_LOGINX /* !HAVE_PUTUTXLINE */
+  loginx (&utx, 0, LOGIN_PROCESS);
+# endif /* HAVE_LOGINX && !HAVE_PUTUTXLINE */
+
+#else /* !HAVE_UTMPX_H */
+# ifdef HAVE_PUTUTLINE
+  setutent ();
   pututline (&utx);
-# ifdef HAVE_UPDWTMP
+#  ifdef HAVE_UPDWTMP
   updwtmp (PATH_WTMP, &utx);
-# else
+#  elif defined HAVE_LOGWTMP /* !HAVE_UPDWTMP */
   logwtmp (line, user, id);
-# endif
+#  endif /* wtmp updating */
   endutent ();
-#else
+# elif defined HAVE_LOGIN /* !HAVE_PUTUTLINE */
   login (&utx);
-#endif
+# endif /* HAVE_LOGIN && !HAVE_PUTUTLINE */
+#endif /* !HAVE_UTMPX_H */
 }
 
 /* utmp_ptsid - generate utmp id for pseudo terminal */
diff --git a/libinetutils/utmp_logout.c b/libinetutils/utmp_logout.c
index 5cc8543..1cab5b8 100644
--- a/libinetutils/utmp_logout.c
+++ b/libinetutils/utmp_logout.c
@@ -38,17 +38,20 @@
  */
 
 /* Written by Wietse Venema.  With port to GNU Inetutils done by Alain
-   Magloire.  */
+   Magloire.  Reorganized to cope with full variation between utmpx
+   and utmp, with different API sets, by Mats Erik Andersson.  */
 
 #include <config.h>
 
 #include <sys/types.h>
 #include <sys/time.h>
 #include <time.h>
-#if defined UTMPX && defined HAVE_UTMPX_H
-# define __USE_GNU
+#ifdef HAVE_UTMPX_H
+# ifndef __USE_GNU
+#  define __USE_GNU 1
+# endif
 # include <utmpx.h>
-#else
+#else /* !HAVE_UTMPX_H */
 # if HAVE_UTIL_H
 #  include <util.h>
 # endif
@@ -61,66 +64,100 @@
 void
 utmp_logout (char *line)
 {
-#ifdef UTMPX
+#ifdef HAVE_UTMPX_H
   struct utmpx utx;
   struct utmpx *ut;
 
   strncpy (utx.ut_line, line, sizeof (utx.ut_line));
 
+# ifdef HAVE_PUTUTXLINE
+  setutxent();
   ut = getutxline (&utx);
   if (ut)
     {
       struct timeval tv;
 
       ut->ut_type = DEAD_PROCESS;
-      ut->ut_exit.e_termination = 0;
-      ut->ut_exit.e_exit = 0;
+#  ifdef HAVE_STRUCT_UTMPX_UT_EXIT
+      memset (&ut->ut_exit, 0, sizeof (ut->ut_exit));
+#  endif
       gettimeofday (&tv, 0);
       ut->ut_tv.tv_sec = tv.tv_sec;
       ut->ut_tv.tv_usec = tv.tv_usec;
+#  ifdef HAVE_STRUCT_UTMPX_UT_USER
+      memset (&ut->ut_user, 0, sizeof (ut->ut_user));
+#  elif defined HAVE_STRUCT_UTMPX_UT_NAME
+      memset (&ut->ut_name, 0, sizeof (ut->ut_name));
+#  endif
+#  ifdef HAVE_STRUCT_UTMPX_UT_HOST
+      memset (ut->ut_host, 0, sizeof (ut->ut_host));
+#   ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
+      ut->ut_syslen = 1;       /* Counting NUL.  */
+#   endif
+#  endif /* UT_HOST */
       pututxline (ut);
+      /* Some systems perform wtmp updating
+       * already in calling pututxline().
+       */
+#  ifdef HAVE_UPDWTMPX
       updwtmpx (PATH_WTMPX, ut);
+#  elif defined HAVE_LOGWTMPX
+      logwtmpx (ut->ut_line, "", "", 0, DEAD_PROCESS);
+#  endif
     }
   endutxent ();
-#elif HAVE_DECL_GETUTENT
+# elif defined HAVE_LOGOUTX /* !HAVE_PUTUTXLINE */
+  if (logoutx (line, 0, DEAD_PROCESS))
+    logwtmpx (line, "", "", 0, DEAD_PROCESS);
+# endif /* HAVE_LOGOUTX */
+
+#else /* !HAVE_UTMPX_H */
   struct utmp utx;
   struct utmp *ut;
 
   strncpy (utx.ut_line, line, sizeof (utx.ut_line));
 
+# ifdef HAVE_PUTUTLINE
+  setutent();
   ut = getutline (&utx);
   if (ut)
     {
-# ifdef HAVE_STRUCT_UTMP_UT_TV
+#  ifdef HAVE_STRUCT_UTMP_UT_TV
       struct timeval tv;
-# endif
+#  endif
 
-# ifdef HAVE_STRUCT_UTMP_UT_TYPE
+#  ifdef HAVE_STRUCT_UTMP_UT_TYPE
       ut->ut_type = DEAD_PROCESS;
-# endif
-# ifdef HAVE_STRUCT_UTMP_UT_EXIT
-      ut->ut_exit.e_termination = 0;
-      ut->ut_exit.e_exit = 0;
-# endif
-# ifdef HAVE_STRUCT_UTMP_UT_TV
+#  endif
+#  ifdef HAVE_STRUCT_UTMP_UT_EXIT
+      memset (&ut->ut_exit, 0, sizeof (ut->ut_exit));
+#  endif
+#  ifdef HAVE_STRUCT_UTMP_UT_TV
       gettimeofday (&tv, 0);
       ut->ut_tv.tv_sec = tv.tv_sec;
       ut->ut_tv.tv_usec = tv.tv_usec;
-# else
+#  else /* !HAVE_STRUCT_UTMP_UT_TV */
       time (&(ut->ut_time));
-# endif
+#  endif
+#  ifdef HAVE_STRUCT_UTMP_UT_USER
+      memset (&ut->ut_user, 0, sizeof (ut->ut_user));
+#  elif defined HAVE_STRUCT_UTMP_UT_NAME
+      memset (&ut->ut_name, 0, sizeof (ut->ut_name));
+#  endif
+#  ifdef HAVE_STRUCT_UTMP_UT_HOST
+      memset (ut->ut_host, 0, sizeof (ut->ut_host));
+#  endif
       pututline (ut);
-# ifdef HAVE_UPDWTMP
-      ut->ut_name[0] = 0;
-      ut->ut_host[0] = 0;
+#  ifdef HAVE_UPDWTMP
       updwtmp (WTMP_FILE, ut);
-# else
+#  elif defined HAVE_LOGWTMP /* !HAVE_UPDWTMP */
       logwtmp (ut->ut_line, "", "");
-# endif
+#  endif
     }
   endutent ();
-#else
+# elif defined HAVE_LOGOUT /* !HAVE_PUTUTLINE */
   if (logout (line))
     logwtmp (line, "", "");
+# endif /* HAVE_LOGOUT */
 #endif
 }
diff --git a/libls/print.c b/libls/print.c
index 9537652..062aca6 100644
--- a/libls/print.c
+++ b/libls/print.c
@@ -63,7 +63,6 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
 #include <filemode.h>
 
 #ifdef HAVE_SYS_MKDEV_H
diff --git a/paths b/paths
index 8cd8096..7e6a24f 100644
--- a/paths
+++ b/paths
@@ -84,10 +84,10 @@ PATH_INETDCONF      $(sysconfdir)/inetd.conf
 PATH_INETDDIR  $(sysconfdir)/inetd.d
 PATH_INETDPID  $(localstatedir)/run/inetd.pid
 PATH_UTMP      <utmp.h> <utmp.h>:UTMP_FILE $(localstatedir)/run/utmp 
search:utmp:/var/run:/var/adm:/etc
-PATH_UTMPX     <utmpx.h> <utmpx.h>:UTMPX_FILE $(localstatedir)/run/utmpx 
search:utmpx:/var/run:/var/adm:/etc
+PATH_UTMPX     <utmpx.h> <utmpx.h>:UTMPX_FILE $(localstatedir)/run/utmpx 
search:utmpx:/var/run:/var/adm:/etc "/var/run/utx.active"
 PATH_WTMP      <utmp.h> <utmp.h>:WTMP_FILE $(localstatedir)/log/wtmp 
search:wtmp:/var/log:/var/adm:/etc
-PATH_WTMPX     <utmpx.h> <utmpx.h>:WTMPX_FILE $(localstatedir)/log/wtmpx 
search:wtmpx:/var/log:/var/adm:/etc
-PATH_LASTLOG   <utmp.h> $(localstatedir)/log/lastlog 
search:lastlog:/var/log:/var/adm:/etc
+PATH_WTMPX     <utmpx.h> <utmpx.h>:WTMPX_FILE $(localstatedir)/log/wtmpx 
search:wtmpx:/var/log:/var/adm:/etc "/var/log/utx.log"
+PATH_LASTLOG   <utmp.h> $(localstatedir)/log/lastlog 
search:lastlog:/var/log:/var/adm:/etc "/var/log/utx.lastlogin"
 PATH_LOG       <syslog.h> /dev/log
 PATH_KLOG      <syslog.h> /dev/klog no
 PATH_LOGCONF   $(sysconfdir)/syslog.conf
diff --git a/src/rlogind.c b/src/rlogind.c
index cd021da..4af17cd 100644
--- a/src/rlogind.c
+++ b/src/rlogind.c
@@ -781,20 +781,13 @@ setup_tty (int fd, struct auth_data *ap)
   ap->env[1] = 0;
 }
 
-#ifdef UTMPX
-char *utmp_ptsid ();
- /*FIXME*/ void utmp_init ();
-
 void
-setup_utmp (char *line)
+setup_utmp (char *line, char *host)
 {
   char *ut_id = utmp_ptsid (line, "rl");
 
-  utmp_init (line + sizeof ("/dev/") - 1, ".rlogin", ut_id);
+  utmp_init (line + sizeof ("/dev/") - 1, ".rlogin", ut_id, host);
 }
-#else
-# define setup_utmp(line)
-#endif
 
 void
 exec_login (int authenticated, struct auth_data *ap)
@@ -911,7 +904,7 @@ rlogind_mainloop (int infd, int outfd)
        close (infd);
 
       setup_tty (0, &auth_data);
-      setup_utmp (line);
+      setup_utmp (line, auth_data.hostname);
 
       exec_login (authenticated, &auth_data);
       fatal (infd, "can't execute login", 1);
@@ -1668,7 +1661,7 @@ cleanup (int signo _GL_UNUSED_PARAMETER)
   char *p;
 
   p = line + sizeof (PATH_DEV) - 1;
-#ifdef UTMPX
+#if !defined HAVE_LOGOUT || !defined HAVE_LOGWTMP
   utmp_logout (p);
   chmod (line, 0644);
   chown (line, 0, 0);
diff --git a/src/uucpd.c b/src/uucpd.c
index e16b995..0699420 100644
--- a/src/uucpd.c
+++ b/src/uucpd.c
@@ -77,6 +77,9 @@
 # include <crypt.h>
 #endif
 #include <termios.h>
+#ifdef HAVE_UTMPX_H
+# include <utmpx.h>
+#endif
 #ifdef HAVE_UTMP_H
 # include <utmp.h>
 #endif
@@ -228,7 +231,30 @@ dologout (void)
     {
       char line[100];
       sprintf (line, "uucp%.4d", pid);
+#ifdef HAVE_LOGWTMPX
+      logwtmpx (line, "", "", 0, DEAD_PROCESS);
+#elif defined HAVE_LOGWTMP
       logwtmp (line, "", "");
+#elif defined HAVE_PUTUTXLINE
+      {
+       /* Novelty in FreeBSD 9.0.  */
+       struct utmpx ut;
+       struct timeval now;
+
+       ut.ut_type = DEAD_PROCESS;
+       ut.ut_pid = pid;
+       strncpy (ut.ut_line, line, sizeof (ut.ut_line));
+       memset (ut.ut_user, 0, sizeof (ut.ut_user));
+       memset (ut.ut_host, 0, sizeof (ut.ut_host));
+# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
+       ut.ut_syslen = 1;
+# endif
+       gettimeofday (&now, NULL);
+       ut.ut_tv.tv_sec = now.tv_sec;
+       ut.ut_tv.tv_usec = now.tv_usec;
+       pututxline (&ut);
+      }
+#endif /* HAVE_PUTUTXLINE && !HAVE_LOGWTMPX && !HAVE_LOGWTMP */
     }
 }
 
@@ -254,7 +280,30 @@ dologin (struct passwd *pw, struct sockaddr_in *sin)
 
   sprintf (line, "uucp%.4d", getpid ());
 
+#ifdef HAVE_LOGWTMPX
+  logwtmpx (line, pw->pw_name, remotehost, 0, USER_PROCESS);
+#elif defined HAVE_LOGWTMP
   logwtmp (line, pw->pw_name, remotehost);
+#elif defined HAVE_PUTUTXLINE
+  {
+    /* Novelty in FreeBSD 9.0.  */
+    struct utmpx ut;
+    struct timeval now;
+
+    ut.ut_type = USER_PROCESS;
+    ut.ut_pid = getpid();
+    strncpy (ut.ut_line, line, sizeof (ut.ut_line));
+    strncpy (ut.ut_user, pw->pw_name, sizeof (ut.ut_user));
+    strncpy (ut.ut_host, remotehost, sizeof (ut.ut_host));
+# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
+       ut.ut_syslen = strlen (remotehost) + 1;
+# endif
+    gettimeofday (&now, NULL);
+    ut.ut_tv.tv_sec = now.tv_sec;
+    ut.ut_tv.tv_usec = now.tv_usec;
+    pututxline (&ut);
+  }
+#endif /* HAVE_PUTUTXLINE && !HAVE_LOGWTMPX && !HAVE_LOGWTMP */
 
 #if defined PATH_LASTLOG && defined HAVE_STRUCT_LASTLOG
 # define SCPYN(a, b)   strncpy(a, b, sizeof (a))
diff --git a/telnetd/pty.c b/telnetd/pty.c
index 2ec2dac..d333a88 100644
--- a/telnetd/pty.c
+++ b/telnetd/pty.c
@@ -29,10 +29,10 @@
 #include <libinetutils.h>
 
 void
-setup_utmp (char *line)
+setup_utmp (char *line, char *host)
 {
   char *ut_id = utmp_ptsid (line, "tn");
-  utmp_init (line + sizeof ("/dev/") - 1, ".telnet", ut_id);
+  utmp_init (line + sizeof ("/dev/") - 1, ".telnet", ut_id, host);
 }
 
 
@@ -73,9 +73,7 @@ startslave (char *host, int autologin, char *autoname)
       if (net > 2)
        close (net);
 
-#ifdef UTMPX
-      setup_utmp (line);
-#endif
+      setup_utmp (line, host);
       start_login (host, autologin, line);
     }
 

http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=5d9c59cbcd0c9967986e1a14907ea1d87e8a5d9c


commit 5d9c59cbcd0c9967986e1a14907ea1d87e8a5d9c
Author: Mats Erik Andersson <address@hidden>
Date:   Sun Jul 29 22:51:18 2012 +0200

    Out-of-tree binary build.

diff --git a/ChangeLog b/ChangeLog
index 6a7a022..6a409fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-07-29  Mats Erik Andersson  <address@hidden>
+
+       Out-of-tree build with libshishi.
+
+       * telnet/Makefile.am (INCLUDES): Add `-I$(top_srcdir)'.
+
+       Obsolete source file.
+
+       * libtelnet/Makefile.am (libtelnet_a_SOURCES): Remove
+       reference to `getent.c'.
+
 2012-07-27  Mats Erik Andersson  <address@hidden>
 
        rlogin, rshd: Protocol coherence.
diff --git a/libtelnet/Makefile.am b/libtelnet/Makefile.am
index fe88c68..87cb583 100644
--- a/libtelnet/Makefile.am
+++ b/libtelnet/Makefile.am
@@ -22,6 +22,6 @@ INCLUDES = $(iu_INCLUDES) $(INCAUTH)
 
 noinst_LIBRARIES = libtelnet.a
 
-libtelnet_a_SOURCES = auth.c enc_des.c encrypt.c forward.c genget.c getent.c 
kerberos.c kerberos5.c misc.c read_passwd.c shishi.c
+libtelnet_a_SOURCES = auth.c enc_des.c encrypt.c forward.c genget.c kerberos.c 
kerberos5.c misc.c read_passwd.c shishi.c
 
 noinst_HEADERS = auth-proto.h auth.h enc-proto.h encrypt.h genget.h 
key-proto.h misc-proto.h misc.h
diff --git a/telnet/Makefile.am b/telnet/Makefile.am
index b37ed35..a18f9a0 100644
--- a/telnet/Makefile.am
+++ b/telnet/Makefile.am
@@ -27,7 +27,7 @@ telnet_SOURCES = authenc.c commands.c main.c network.c ring.c 
sys_bsd.c \
 
 noinst_HEADERS = defines.h externs.h general.h ring.h types.h
 
-INCLUDES = $(iu_INCLUDES) $(NCURSES_INCLUDE)
+INCLUDES = $(iu_INCLUDES) -I$(top_srcdir) $(NCURSES_INCLUDE)
 AM_CPPFLAGS = -DTERMCAP -DLINEMODE -DKLUDGELINEMODE -DENV_HACK
 
 LDADD = $(iu_LIBRARIES) $(top_builddir)/libtelnet/libtelnet.a $(LIBTERMCAP) 
$(LIBCRYPT) $(LIBAUTH)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                   |   71 +++++++++++++++++++++++++++++++++++
 configure.ac                |   59 +++++++++++++++++++++++-----
 libinetutils/cleansess.c    |    7 ++-
 libinetutils/libinetutils.h |    2 +-
 libinetutils/logwtmp.c      |   56 ++++++++++++++++++++-------
 libinetutils/logwtmpko.c    |   38 +++++++++++-------
 libinetutils/utmp_init.c    |   78 +++++++++++++++++++++++++++-----------
 libinetutils/utmp_logout.c  |   87 ++++++++++++++++++++++++++++++------------
 libls/print.c               |    1 -
 libtelnet/Makefile.am       |    2 +-
 paths                       |    6 +-
 src/rlogind.c               |   15 ++-----
 src/uucpd.c                 |   49 ++++++++++++++++++++++++
 telnet/Makefile.am          |    2 +-
 telnetd/pty.c               |    8 +--
 15 files changed, 368 insertions(+), 113 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]