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 ...@@ -2,7 +2,7 @@ dnl MU_CHECK_UTMP -- Check for the presence of utmp.h, setutent, getutent
2 dnl and endutent calls. 2 dnl and endutent calls.
3 AC_DEFUN([MU_CHECK_UTMP], 3 AC_DEFUN([MU_CHECK_UTMP],
4 [ 4 [
5 AC_CHECK_HEADERS([utmp.h]) 5 AC_CHECK_HEADERS([utmp.h utmpx.h])
6 # The three functions setutent,getutent and endutent depend on each other, 6 # The three functions setutent,getutent and endutent depend on each other,
7 # so it seems reasonable to provide replacements for all three if getutent 7 # so it seems reasonable to provide replacements for all three if getutent
8 # is not present. 8 # is not present.
...@@ -11,4 +11,10 @@ AC_DEFUN([MU_CHECK_UTMP], ...@@ -11,4 +11,10 @@ AC_DEFUN([MU_CHECK_UTMP],
11 [Define if your system has the three ???utent functions]), 11 [Define if your system has the three ???utent functions]),
12 [if test "$ac_cv_header_utmp_h" = "yes"; then 12 [if test "$ac_cv_header_utmp_h" = "yes"; then
13 AC_LIBOBJ([utmp]) 13 AC_LIBOBJ([utmp])
14 fi])]) 14 fi])
15 if test "$ac_cv_header_utmp_h" = "yes"; then
16 AC_CHECK_MEMBERS([struct utmp.ut_user, struct utmp.ut_name],,,
17 [#include <sys/types.h>
18 #include <utmp.h>])
19 fi
20 ])
......
...@@ -36,10 +36,8 @@ extern void setutent (void); ...@@ -36,10 +36,8 @@ extern void setutent (void);
36 extern struct utmp *getutent (void); 36 extern struct utmp *getutent (void);
37 #endif 37 #endif
38 38
39 #ifdef UTMPX 39 #ifdef HAVE_UTMPX_H
40 # ifdef HAVE_UTMPX_H 40 # include <utmpx.h>
41 # include <utmpx.h>
42 # endif
43 typedef struct utmpx UTMP; 41 typedef struct utmpx UTMP;
44 # define SETUTENT() setutxent() 42 # define SETUTENT() setutxent()
45 # define GETUTENT() getutxent() 43 # define GETUTENT() getutxent()
...@@ -49,6 +47,13 @@ typedef struct utmp UTMP; ...@@ -49,6 +47,13 @@ typedef struct utmp UTMP;
49 # define SETUTENT() setutent() 47 # define SETUTENT() setutent()
50 # define GETUTENT() getutent() 48 # define GETUTENT() getutent()
51 # define ENDUTENT() endutent() 49 # define ENDUTENT() endutent()
50 # if !HAVE_STRUCT_UTMP_UT_USER
51 # if HAVE_STRUCT_UTMP_UT_NAME
52 # define ut_user ut_name
53 # else
54 # error "Neither ut_user nor ut_name found in struct utmp. Please report."
55 # endif
56 # endif
52 #endif 57 #endif
53 58
54 #define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line)) 59 #define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line))
...@@ -462,7 +467,7 @@ find_user (const char *name, char *tty) ...@@ -462,7 +467,7 @@ find_user (const char *name, char *tty)
462 if (uptr->ut_type != USER_PROCESS) 467 if (uptr->ut_type != USER_PROCESS)
463 continue; 468 continue;
464 #endif 469 #endif
465 if (!strncmp (uptr->ut_name, name, sizeof(uptr->ut_name))) 470 if (!strncmp (uptr->ut_user, name, sizeof(uptr->ut_user)))
466 { 471 {
467 /* no particular tty was requested */ 472 /* no particular tty was requested */
468 strncpy (ftty + sizeof(PATH_DEV), 473 strncpy (ftty + sizeof(PATH_DEV),
......