+2019-08-13 Florian Weimer <fweimer@redhat.com>
+
+ * login/getutid_r.c (__getutid_r): _HAVE_UT_ID and _HAVE_UT_TYPE
+ are always true.
+ * login/getutmp.c (getutmp): _HAVE_UT_TYPE, _HAVE_UT_PID,
+ _HAVE_UT_ID, _HAVE_UT_HOST, _HAVE_UT_TV are always true.
+ * login/getutmpx.c (getutmpx): Likewise.
+ * login/login.c (login): _HAVE_UT_TYPE, _HAVE_UT_PID are always
+ true.
+ * login/logout.c (logout): _HAVE_UT_TYPE, _HAVE_UT_HOST,
+ _HAVE_UT_TV are always true.
+ * login/logwtmp.c (logwtmp): _HAVE_UT_PID, _HAVE_UT_TYPE,
+ _HAVE_UT_HOST, _HAVE_UT_TV are always true.
+ * login/tst-utmp.c: _HAVE_UT_TYPE, _HAVE_UT_TV are always true.
+ * login/utmp_file.c (__libc_setutent): _HAVE_UT_TYPE, _HAVE_UT_ID
+ are always true.
+ (internal_getut_r): _HAVE_UT_TYPE is always true.
+ (__libc_pututline): Likewise.
+ * login/programs/utmpdump.c (print_entry): Assume that
+ _HAVE_UT_TYPE, _HAVE_UT_PID, _HAVE_UT_ID, _HAVE_UT_HOST,
+ _HAVE_UT_TV are always true.
+ * sysdeps/generic/utmp-equal.h (__utmp_equal): _HAVE_UT_TYPE,
+ _HAVE_UT_ID are always true.
+ * sysdeps/gnu/bits/utmp.h: Move to ...
+ * bits/utmp.h: ... here, replacing the old file.
+
2019-08-12 Florian Weimer <fweimer@redhat.com>
* elf/Makefile (tests): Unconditionally add tst-dlopen-aout.
-/* The `struct utmp' type, describing entries in the utmp file. Generic/BSDish
+/* The `struct utmp' type, describing entries in the utmp file.
Copyright (C) 1993-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
#endif
#include <paths.h>
-#include <time.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <bits/wordsize.h>
-#define UT_NAMESIZE 8
-#define UT_LINESIZE 8
-#define UT_HOSTSIZE 16
+#define UT_LINESIZE 32
+#define UT_NAMESIZE 32
+#define UT_HOSTSIZE 256
+/* The structure describing an entry in the database of
+ previous logins. */
struct lastlog
{
- time_t ll_time;
+#if __WORDSIZE_TIME64_COMPAT32
+ int32_t ll_time;
+#else
+ __time_t ll_time;
+#endif
char ll_line[UT_LINESIZE];
char ll_host[UT_HOSTSIZE];
};
-struct utmp
+
+/* The structure describing the status of a terminated process. This
+ type is used in `struct utmp' below. */
+struct exit_status
{
- char ut_line[UT_LINESIZE];
- char ut_user[UT_NAMESIZE];
-#define ut_name ut_user
- char ut_host[UT_HOSTSIZE];
- long int ut_time;
+ short int e_termination; /* Process termination status. */
+ short int e_exit; /* Process exit status. */
};
-#define _HAVE_UT_HOST 1 /* We have the ut_host field. */
+/* The structure describing an entry in the user accounting database. */
+struct utmp
+{
+ short int ut_type; /* Type of login. */
+ pid_t ut_pid; /* Process ID of login process. */
+ char ut_line[UT_LINESIZE]
+ __attribute_nonstring__; /* Devicename. */
+ char ut_id[4]; /* Inittab ID. */
+ char ut_user[UT_NAMESIZE]
+ __attribute_nonstring__; /* Username. */
+ char ut_host[UT_HOSTSIZE]
+ __attribute_nonstring__; /* Hostname for remote login. */
+ struct exit_status ut_exit; /* Exit status of a process marked
+ as DEAD_PROCESS. */
+/* The ut_session and ut_tv fields must be the same size when compiled
+ 32- and 64-bit. This allows data files and shared memory to be
+ shared between 32- and 64-bit applications. */
+#if __WORDSIZE_TIME64_COMPAT32
+ int32_t ut_session; /* Session ID, used for windowing. */
+ struct
+ {
+ int32_t tv_sec; /* Seconds. */
+ int32_t tv_usec; /* Microseconds. */
+ } ut_tv; /* Time entry was made. */
+#else
+ long int ut_session; /* Session ID, used for windowing. */
+ struct timeval ut_tv; /* Time entry was made. */
+#endif
+
+ int32_t ut_addr_v6[4]; /* Internet address of remote host. */
+ char __glibc_reserved[20]; /* Reserved for future use. */
+};
+
+/* Backwards compatibility hacks. */
+#define ut_name ut_user
+#ifndef _NO_UT_TIME
+/* We have a problem here: `ut_time' is also used otherwise. Define
+ _NO_UT_TIME if the compiler complains. */
+# define ut_time ut_tv.tv_sec
+#endif
+#define ut_xtime ut_tv.tv_sec
+#define ut_addr ut_addr_v6[0]
+
+
+/* Values for the `ut_type' field of a `struct utmp'. */
+#define EMPTY 0 /* No valid user accounting information. */
+
+#define RUN_LVL 1 /* The system's runlevel. */
+#define BOOT_TIME 2 /* Time of system boot. */
+#define NEW_TIME 3 /* Time after system clock changed. */
+#define OLD_TIME 4 /* Time when system clock changed. */
+
+#define INIT_PROCESS 5 /* Process spawned by the init process. */
+#define LOGIN_PROCESS 6 /* Session leader of a logged in user. */
+#define USER_PROCESS 7 /* Normal process. */
+#define DEAD_PROCESS 8 /* Terminated process. */
+
+#define ACCOUNTING 9
+
+/* Old Linux name for the EMPTY type. */
+#define UT_UNKNOWN EMPTY
+
+
+/* Tell the user that we have a modern system with UT_HOST, UT_PID,
+ UT_TYPE, UT_ID and UT_TV fields. */
+#define _HAVE_UT_TYPE 1
+#define _HAVE_UT_PID 1
+#define _HAVE_UT_ID 1
+#define _HAVE_UT_TV 1
+#define _HAVE_UT_HOST 1
int
__getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result)
{
-#if (_HAVE_UT_ID - 0) && (_HAVE_UT_TYPE - 0)
int retval;
/* Test whether ID has any of the legal types. */
__libc_lock_unlock (__libc_utmp_lock);
return retval;
-#else /* !_HAVE_UT_ID && !_HAVE_UT_TYPE */
- __set_errno (ENOSYS);
- return -1;
-#endif
}
libc_hidden_def (__getutid_r)
weak_alias (__getutid_r, getutid_r)
void
getutmp (const struct utmpx *utmpx, struct utmp *utmp)
{
-#if _HAVE_UT_TYPE - 0
utmp->ut_type = utmpx->ut_type;
-#endif
-#if _HAVE_UT_PID - 0
utmp->ut_pid = utmpx->ut_pid;
-#endif
memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line));
memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user));
-#if _HAVE_UT_ID - 0
memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id));
-#endif
-#if _HAVE_UT_HOST - 0
memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host));
-#endif
-#if _HAVE_UT_TV - 0
utmp->ut_tv = utmpx->ut_tv;
-#else
- utmp->ut_time = utmpx->ut_time;
-#endif
}
getutmpx (const struct utmp *utmp, struct utmpx *utmpx)
{
memset (utmpx, 0, sizeof (struct utmpx));
-
-#if _HAVE_UT_TYPE - 0
utmpx->ut_type = utmp->ut_type;
-#endif
-#if _HAVE_UT_PID - 0
utmpx->ut_pid = utmp->ut_pid;
-#endif
memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line));
memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user));
-#if _HAVE_UT_ID - 0
memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id));
-#endif
-#if _HAVE_UT_HOST - 0
memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host));
-#endif
-#if _HAVE_UT_TV - 0
utmpx->ut_tv = utmp->ut_tv;
-#else
- utmpx->ut_time = utmp->ut_time;
-#endif
}
struct utmp copy = *ut;
/* Fill in those fields we supply. */
-#if _HAVE_UT_TYPE - 0
copy.ut_type = USER_PROCESS;
-#endif
-#if _HAVE_UT_PID - 0
copy.ut_pid = getpid ();
-#endif
/* Seek tty. */
found_tty = tty_name (STDIN_FILENO, &tty, sizeof (_tty));
setutent ();
/* Fill in search information. */
-#if _HAVE_UT_TYPE - 0
tmp.ut_type = USER_PROCESS;
-#endif
strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
/* Read the record. */
{
/* Clear information about who & from where. */
memset (ut->ut_name, '\0', sizeof ut->ut_name);
-#if _HAVE_UT_HOST - 0
memset (ut->ut_host, '\0', sizeof ut->ut_host);
-#endif
-#if _HAVE_UT_TV - 0
struct timeval tv;
__gettimeofday (&tv, NULL);
ut->ut_tv.tv_sec = tv.tv_sec;
ut->ut_tv.tv_usec = tv.tv_usec;
-#else
- ut->ut_time = time (NULL);
-#endif
-#if _HAVE_UT_TYPE - 0
ut->ut_type = DEAD_PROCESS;
-#endif
if (pututline (ut) != NULL)
result = 1;
/* Set information in new entry. */
memset (&ut, 0, sizeof (ut));
-#if _HAVE_UT_PID - 0
ut.ut_pid = getpid ();
-#endif
-#if _HAVE_UT_TYPE - 0
ut.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS;
-#endif
strncpy (ut.ut_line, line, sizeof ut.ut_line);
strncpy (ut.ut_name, name, sizeof ut.ut_name);
-#if _HAVE_UT_HOST - 0
strncpy (ut.ut_host, host, sizeof ut.ut_host);
-#endif
-#if _HAVE_UT_TV - 0
struct timeval tv;
__gettimeofday (&tv, NULL);
ut.ut_tv.tv_sec = tv.tv_sec;
ut.ut_tv.tv_usec = tv.tv_usec;
-#else
- ut.ut_time = time (NULL);
-#endif
updwtmp (_PATH_WTMP, &ut);
}
temp_tv.tv_sec = up->ut_tv.tv_sec;
temp_tv.tv_usec = up->ut_tv.tv_usec;
- (printf) (
- /* The format string. */
-#if _HAVE_UT_TYPE
- "[%d] "
-#endif
-#if _HAVE_UT_PID
- "[%05d] "
-#endif
-#if _HAVE_UT_ID
- "[%-4.4s] "
-#endif
- "[%-8.8s] [%-12.12s]"
-#if _HAVE_UT_HOST
- " [%-16.16s]"
-#endif
- " [%-15.15s]"
-#if _HAVE_UT_TV
- " [%ld]"
-#endif
- "\n"
- /* The arguments. */
-#if _HAVE_UT_TYPE
- , up->ut_type
-#endif
-#if _HAVE_UT_PID
- , up->ut_pid
-#endif
-#if _HAVE_UT_ID
- , up->ut_id
-#endif
- , up->ut_user, up->ut_line
-#if _HAVE_UT_HOST
- , up->ut_host
-#endif
-#if _HAVE_UT_TV
- , 4 + ctime (&temp_tv.tv_sec)
- , (long int) temp_tv.tv_usec
-#else
- , 4 + ctime (&up->ut_time)
-#endif
- );
+ printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-16.16s] [%-15.15s]"
+ " [%ld]\n",
+ up->ut_type, up->ut_pid, up->ut_id, up->ut_user, up->ut_line,
+ up->ut_host, 4 + ctime (&temp_tv.tv_sec),
+ (long int) temp_tv.tv_usec);
}
int
#endif
-#if defined UTMPX || _HAVE_UT_TYPE
-
/* Prototype for our test function. */
static int do_test (int argc, char *argv[]);
struct utmp entry[] =
{
-#if defined UTMPX || _HAVE_UT_TV
#define UT(a) .ut_tv = { .tv_sec = (a)}
-#else
-#define UT(a) .ut_time = (a)
-#endif
{ .ut_type = BOOT_TIME, .ut_pid = 1, UT(1000) },
{ .ut_type = RUN_LVL, .ut_pid = 1, UT(2000) },
entry[n].ut_pid = (entry_pid += 27);
entry[n].ut_type = USER_PROCESS;
strncpy (entry[n].ut_user, user, sizeof (entry[n].ut_user));
-#if defined UTMPX || _HAVE_UT_TV - 0
entry[n].ut_tv.tv_sec = (entry_time += 1000);
-#else
- entry[n].ut_time = (entry_time += 1000);
-#endif
setutent ();
if (pututline (&entry[n]) == NULL)
{
entry[n].ut_type = DEAD_PROCESS;
strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user));
-#if defined UTMPX || _HAVE_UT_TV - 0
entry[n].ut_tv.tv_sec = (entry_time += 1000);
-#else
- entry[n].ut_time = (entry_time += 1000);
-#endif
setutent ();
if (pututline (&entry[n]) == NULL)
return result;
}
-
-#else
-
-/* No field 'ut_type' in struct utmp. */
-int
-main (void)
-{
- return 0;
-}
-
-#endif
file_offset = 0;
/* Make sure the entry won't match. */
-#if _HAVE_UT_TYPE - 0
last_entry.ut_type = -1;
-#else
- last_entry.ut_line[0] = '\177';
-# if _HAVE_UT_ID - 0
- last_entry.ut_id[0] = '\0';
-# endif
-#endif
return 1;
}
LOCKING_FAILED ();
}
-#if _HAVE_UT_TYPE - 0
if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
|| id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
{
}
}
else
-#endif /* _HAVE_UT_TYPE */
{
/* Search for the next entry with the specified ID and with type
INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS. */
file_offset += sizeof (struct utmp);
/* Stop if we found a user or login entry. */
- if (
-#if _HAVE_UT_TYPE - 0
- (last_entry.ut_type == USER_PROCESS
+ if ((last_entry.ut_type == USER_PROCESS
|| last_entry.ut_type == LOGIN_PROCESS)
- &&
-#endif
- !strncmp (line->ut_line, last_entry.ut_line, sizeof line->ut_line))
+ && (strncmp (line->ut_line, last_entry.ut_line, sizeof line->ut_line)
+ == 0))
break;
}
/* Find the correct place to insert the data. */
if (file_offset > 0
- && (
-#if _HAVE_UT_TYPE - 0
- (last_entry.ut_type == data->ut_type
+ && ((last_entry.ut_type == data->ut_type
&& (last_entry.ut_type == RUN_LVL
|| last_entry.ut_type == BOOT_TIME
|| last_entry.ut_type == OLD_TIME
|| last_entry.ut_type == NEW_TIME))
- ||
-#endif
- __utmp_equal (&last_entry, data)))
+ || __utmp_equal (&last_entry, data)))
found = 1;
else
{
static int
__utmp_equal (const struct utmp *entry, const struct utmp *match)
{
- return
- (
-#if _HAVE_UT_TYPE - 0
- (entry->ut_type == INIT_PROCESS
- || entry->ut_type == LOGIN_PROCESS
- || entry->ut_type == USER_PROCESS
- || entry->ut_type == DEAD_PROCESS)
- &&
- (match->ut_type == INIT_PROCESS
- || match->ut_type == LOGIN_PROCESS
- || match->ut_type == USER_PROCESS
- || match->ut_type == DEAD_PROCESS)
- &&
-#endif
-#if _HAVE_UT_ID - 0
- (entry->ut_id[0] && match->ut_id[0]
- ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
- : strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0)
-#else
- strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
-#endif
- );
+ return (entry->ut_type == INIT_PROCESS
+ || entry->ut_type == LOGIN_PROCESS
+ || entry->ut_type == USER_PROCESS
+ || entry->ut_type == DEAD_PROCESS)
+ && (match->ut_type == INIT_PROCESS
+ || match->ut_type == LOGIN_PROCESS
+ || match->ut_type == USER_PROCESS
+ || match->ut_type == DEAD_PROCESS)
+ && (entry->ut_id[0] && match->ut_id[0]
+ ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
+ : (strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line)
+ == 0));
}
+++ /dev/null
-/* The `struct utmp' type, describing entries in the utmp file. GNU version.
- Copyright (C) 1993-2019 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-#ifndef _UTMP_H
-# error "Never include <bits/utmp.h> directly; use <utmp.h> instead."
-#endif
-
-#include <paths.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <bits/wordsize.h>
-
-
-#define UT_LINESIZE 32
-#define UT_NAMESIZE 32
-#define UT_HOSTSIZE 256
-
-
-/* The structure describing an entry in the database of
- previous logins. */
-struct lastlog
- {
-#if __WORDSIZE_TIME64_COMPAT32
- int32_t ll_time;
-#else
- __time_t ll_time;
-#endif
- char ll_line[UT_LINESIZE];
- char ll_host[UT_HOSTSIZE];
- };
-
-
-/* The structure describing the status of a terminated process. This
- type is used in `struct utmp' below. */
-struct exit_status
- {
- short int e_termination; /* Process termination status. */
- short int e_exit; /* Process exit status. */
- };
-
-
-/* The structure describing an entry in the user accounting database. */
-struct utmp
-{
- short int ut_type; /* Type of login. */
- pid_t ut_pid; /* Process ID of login process. */
- char ut_line[UT_LINESIZE]
- __attribute_nonstring__; /* Devicename. */
- char ut_id[4]; /* Inittab ID. */
- char ut_user[UT_NAMESIZE]
- __attribute_nonstring__; /* Username. */
- char ut_host[UT_HOSTSIZE]
- __attribute_nonstring__; /* Hostname for remote login. */
- struct exit_status ut_exit; /* Exit status of a process marked
- as DEAD_PROCESS. */
-/* The ut_session and ut_tv fields must be the same size when compiled
- 32- and 64-bit. This allows data files and shared memory to be
- shared between 32- and 64-bit applications. */
-#if __WORDSIZE_TIME64_COMPAT32
- int32_t ut_session; /* Session ID, used for windowing. */
- struct
- {
- int32_t tv_sec; /* Seconds. */
- int32_t tv_usec; /* Microseconds. */
- } ut_tv; /* Time entry was made. */
-#else
- long int ut_session; /* Session ID, used for windowing. */
- struct timeval ut_tv; /* Time entry was made. */
-#endif
-
- int32_t ut_addr_v6[4]; /* Internet address of remote host. */
- char __glibc_reserved[20]; /* Reserved for future use. */
-};
-
-/* Backwards compatibility hacks. */
-#define ut_name ut_user
-#ifndef _NO_UT_TIME
-/* We have a problem here: `ut_time' is also used otherwise. Define
- _NO_UT_TIME if the compiler complains. */
-# define ut_time ut_tv.tv_sec
-#endif
-#define ut_xtime ut_tv.tv_sec
-#define ut_addr ut_addr_v6[0]
-
-
-/* Values for the `ut_type' field of a `struct utmp'. */
-#define EMPTY 0 /* No valid user accounting information. */
-
-#define RUN_LVL 1 /* The system's runlevel. */
-#define BOOT_TIME 2 /* Time of system boot. */
-#define NEW_TIME 3 /* Time after system clock changed. */
-#define OLD_TIME 4 /* Time when system clock changed. */
-
-#define INIT_PROCESS 5 /* Process spawned by the init process. */
-#define LOGIN_PROCESS 6 /* Session leader of a logged in user. */
-#define USER_PROCESS 7 /* Normal process. */
-#define DEAD_PROCESS 8 /* Terminated process. */
-
-#define ACCOUNTING 9
-
-/* Old Linux name for the EMPTY type. */
-#define UT_UNKNOWN EMPTY
-
-
-/* Tell the user that we have a modern system with UT_HOST, UT_PID,
- UT_TYPE, UT_ID and UT_TV fields. */
-#define _HAVE_UT_TYPE 1
-#define _HAVE_UT_PID 1
-#define _HAVE_UT_ID 1
-#define _HAVE_UT_TV 1
-#define _HAVE_UT_HOST 1