Disable utmpx permanently

On Linux, utmpx and utmp are identical.  However, documentation (manual
pages) covers utmp, and just says about utmpx that it's identical to
utmp.  It seems that it's preferred to use utmp, at least by reading the
manual pages.

Moreover, we were defaulting to utmp (utmpx had to be explicitly enabled
at configuration time).  So, it seems safer to just make it permanent,
which should not affect default builds.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2022-12-21 18:33:40 +01:00
committed by Iker Pedrosa
parent 2da7607ea6
commit 170b76cdd1
9 changed files with 6 additions and 309 deletions

View File

@@ -107,11 +107,7 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
static void update_utmp (const char *user,
const char *tty,
const char *host,
#ifdef USE_UTMPX
/*@null@*/const struct utmpx *utent
#else
/*@null@*/const struct utmp *utent
#endif
);
#ifndef USE_PAM
@@ -462,26 +458,13 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
static void update_utmp (const char *user,
const char *tty,
const char *host,
#ifdef USE_UTMPX
/*@null@*/const struct utmpx *utent
#else
/*@null@*/const struct utmp *utent
#endif
)
{
#ifdef USE_UTMPX
struct utmpx *utx = prepare_utmpx (user, tty, host, utent);
#else
struct utmp *ut = prepare_utmp (user, tty, host, utent);
#endif /* USE_UTMPX */
#ifndef USE_UTMPX
(void) setutmp (ut); /* make entry in the utmp & wtmp files */
free (ut);
#else
(void) setutmpx (utx); /* make entry in the utmpx & wtmpx files */
free (utx);
#endif /* USE_UTMPX */
}
/*
@@ -526,11 +509,7 @@ int main (int argc, char **argv)
struct passwd *pwd = NULL;
char **envp = environ;
const char *failent_user;
#ifdef USE_UTMPX
/*@null@*/struct utmpx *utent;
#else
/*@null@*/struct utmp *utent;
#endif
#ifdef USE_PAM
int retcode;
@@ -674,7 +653,7 @@ int main (int argc, char **argv)
if (rflg || hflg) {
cp = hostname;
#if defined(HAVE_STRUCT_UTMP_UT_HOST) || defined(USE_UTMPX)
#if defined(HAVE_STRUCT_UTMP_UT_HOST)
} else if ((NULL != utent) && ('\0' != utent->ut_host[0])) {
cp = utent->ut_host;
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
@@ -1036,19 +1015,11 @@ int main (int argc, char **argv)
failure (pwd->pw_uid, tty, &faillog);
}
if (getdef_str ("FTMP_FILE") != NULL) {
#ifdef USE_UTMPX
struct utmpx *failent =
prepare_utmpx (failent_user,
tty,
/* FIXME: or fromhost? */hostname,
utent);
#else /* !USE_UTMPX */
struct utmp *failent =
prepare_utmp (failent_user,
tty,
hostname,
utent);
#endif /* !USE_UTMPX */
failtmp (failent_user, failent);
free (failent);
}

View File

@@ -32,21 +32,13 @@ const char *Prog;
#endif
/* local function prototypes */
#ifdef USE_UTMPX
static int check_login (const struct utmpx *ut);
#else /* !USE_UTMPX */
static int check_login (const struct utmp *ut);
#endif /* !USE_UTMPX */
static void send_mesg_to_tty (int tty_fd);
/*
* check_login - check if user (struct utmpx/utmp) allowed to stay logged in
* check_login - check if user (struct utmp) allowed to stay logged in
*/
#ifdef USE_UTMPX
static int check_login (const struct utmpx *ut)
#else /* !USE_UTMPX */
static int check_login (const struct utmp *ut)
#endif /* !USE_UTMPX */
{
char user[sizeof (ut->ut_user) + 1];
time_t now;
@@ -116,7 +108,7 @@ static void send_mesg_to_tty (int tty_fd)
*
* logoutd is started at system boot time and enforces the login
* time and port restrictions specified in /etc/porttime. The
* utmpx/utmp file is periodically scanned and offending users are logged
* utmp file is periodically scanned and offending users are logged
* off from the system.
*/
int main (int argc, char **argv)
@@ -125,11 +117,7 @@ int main (int argc, char **argv)
int status;
pid_t pid;
#ifdef USE_UTMPX
struct utmpx *ut;
#else /* !USE_UTMPX */
struct utmp *ut;
#endif /* !USE_UTMPX */
char user[sizeof (ut->ut_user) + 1]; /* terminating NUL */
char tty_name[sizeof (ut->ut_line) + 6]; /* /dev/ + NUL */
int tty_fd;
@@ -171,31 +159,23 @@ int main (int argc, char **argv)
OPENLOG ("logoutd");
/*
* Scan the utmpx/utmp file once per minute looking for users that
* Scan the utmp file once per minute looking for users that
* are not supposed to still be logged in.
*/
while (true) {
/*
* Attempt to re-open the utmpx/utmp file. The file is only
* Attempt to re-open the utmp file. The file is only
* open while it is being used.
*/
#ifdef USE_UTMPX
setutxent ();
#else /* !USE_UTMPX */
setutent ();
#endif /* !USE_UTMPX */
/*
* Read all of the entries in the utmpx/utmp file. The entries
* Read all of the entries in the utmp file. The entries
* for login sessions will be checked to see if the user
* is permitted to be signed on at this time.
*/
#ifdef USE_UTMPX
while ((ut = getutxent ()) != NULL)
#else /* !USE_UTMPX */
while ((ut = getutent ()) != NULL)
#endif /* !USE_UTMPX */
{
if (ut->ut_type != USER_PROCESS) {
continue;
@@ -259,11 +239,7 @@ int main (int argc, char **argv)
exit (EXIT_SUCCESS);
}
#ifdef USE_UTMPX
endutxent ();
#else /* !USE_UTMPX */
endutent ();
#endif /* !USE_UTMPX */
#ifndef DEBUG
sleep (60);