Commit b4d7b1a6 b4d7b1a6cb3f17fdce8759ded4ade0188e86d20d by Sergey Poznyakoff

Fix the use of struct utmp/utmpx in comsatd.

* am/utmp.m4: Check if struct utmp has ut_user or ut_name members.
* comsat/comsat.c [HAVE_UTMPX_H]: Define UTMP as a typedef of
struct utmpx.
Define ut_user, if necessary.
(find_user): Use ut_user instead of (backward-compatible) ut_name.
1 parent c2149578
......@@ -2,7 +2,7 @@ dnl MU_CHECK_UTMP -- Check for the presence of utmp.h, setutent, getutent
dnl and endutent calls.
AC_DEFUN([MU_CHECK_UTMP],
[
AC_CHECK_HEADERS([utmp.h])
AC_CHECK_HEADERS([utmp.h utmpx.h])
# The three functions setutent,getutent and endutent depend on each other,
# so it seems reasonable to provide replacements for all three if getutent
# is not present.
......@@ -11,4 +11,10 @@ AC_DEFUN([MU_CHECK_UTMP],
[Define if your system has the three ???utent functions]),
[if test "$ac_cv_header_utmp_h" = "yes"; then
AC_LIBOBJ([utmp])
fi])])
fi])
if test "$ac_cv_header_utmp_h" = "yes"; then
AC_CHECK_MEMBERS([struct utmp.ut_user, struct utmp.ut_name],,,
[#include <sys/types.h>
#include <utmp.h>])
fi
])
......
......@@ -36,10 +36,8 @@ extern void setutent (void);
extern struct utmp *getutent (void);
#endif
#ifdef UTMPX
# ifdef HAVE_UTMPX_H
#ifdef HAVE_UTMPX_H
# include <utmpx.h>
# endif
typedef struct utmpx UTMP;
# define SETUTENT() setutxent()
# define GETUTENT() getutxent()
......@@ -49,6 +47,13 @@ typedef struct utmp UTMP;
# define SETUTENT() setutent()
# define GETUTENT() getutent()
# define ENDUTENT() endutent()
# if !HAVE_STRUCT_UTMP_UT_USER
# if HAVE_STRUCT_UTMP_UT_NAME
# define ut_user ut_name
# else
# error "Neither ut_user nor ut_name found in struct utmp. Please report."
# endif
# endif
#endif
#define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line))
......@@ -462,7 +467,7 @@ find_user (const char *name, char *tty)
if (uptr->ut_type != USER_PROCESS)
continue;
#endif
if (!strncmp (uptr->ut_name, name, sizeof(uptr->ut_name)))
if (!strncmp (uptr->ut_user, name, sizeof(uptr->ut_user)))
{
/* no particular tty was requested */
strncpy (ftty + sizeof(PATH_DEV),
......