Blame man5/utmp.5

Packit 7cfc04
.\" Copyright (c) 1993 Michael Haardt (michael@cantor.informatik.rwth-aachen.de),
Packit 7cfc04
.\" Fri Apr  2 11:32:09 MET DST 1993
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
Packit 7cfc04
.\" This is free documentation; you can redistribute it and/or
Packit 7cfc04
.\" modify it under the terms of the GNU General Public License as
Packit 7cfc04
.\" published by the Free Software Foundation; either version 2 of
Packit 7cfc04
.\" the License, or (at your option) any later version.
Packit 7cfc04
.\"
Packit 7cfc04
.\" The GNU General Public License's references to "object code"
Packit 7cfc04
.\" and "executables" are to be interpreted as the output of any
Packit 7cfc04
.\" document formatting or typesetting system, including
Packit 7cfc04
.\" intermediate and printed output.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This manual is distributed in the hope that it will be useful,
Packit 7cfc04
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 7cfc04
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 7cfc04
.\" GNU General Public License for more details.
Packit 7cfc04
.\"
Packit 7cfc04
.\" You should have received a copy of the GNU General Public
Packit 7cfc04
.\" License along with this manual; if not, see
Packit 7cfc04
.\" <http://www.gnu.org/licenses/>.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified 1993-07-25 by Rik Faith (faith@cs.unc.edu)
Packit 7cfc04
.\" Modified 1995-02-26 by Michael Haardt
Packit 7cfc04
.\" Modified 1996-07-20 by Michael Haardt
Packit 7cfc04
.\" Modified 1997-07-02 by Nicolás Lichtmaier <nick@debian.org>
Packit 7cfc04
.\" Modified 2004-10-31 by aeb, following Gwenole Beauchesne
Packit 7cfc04
.TH UTMP 5 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
utmp, wtmp \- login records
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <utmp.h>
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.I utmp
Packit 7cfc04
file allows one to discover information about who is currently using the
Packit 7cfc04
system.
Packit 7cfc04
There may be more users currently using the system, because not
Packit 7cfc04
all programs use utmp logging.
Packit 7cfc04
.PP
Packit 7cfc04
.B Warning:
Packit 7cfc04
.I utmp
Packit 7cfc04
must not be writable by the user class "other",
Packit 7cfc04
because many system programs (foolishly)
Packit 7cfc04
depend on its integrity.
Packit 7cfc04
You risk faked system logfiles and
Packit 7cfc04
modifications of system files if you leave
Packit 7cfc04
.I utmp
Packit 7cfc04
writable to any user other than the owner and group owner of the file.
Packit 7cfc04
.PP
Packit 7cfc04
The file is a sequence of
Packit 7cfc04
.I utmp
Packit 7cfc04
structures,
Packit 7cfc04
declared as follows in
Packit 7cfc04
.IR <utmp.h>
Packit 7cfc04
(note that this is only one of several definitions
Packit 7cfc04
around; details depend on the version of libc):
Packit 7cfc04
.in
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
/* Values for ut_type field, below */
Packit 7cfc04
Packit 7cfc04
#define EMPTY         0 /* Record does not contain valid info
Packit 7cfc04
                           (formerly known as UT_UNKNOWN on Linux) */
Packit 7cfc04
#define RUN_LVL       1 /* Change in system run-level (see
Packit 7cfc04
                           \fBinit\fP(8)) */
Packit 7cfc04
#define BOOT_TIME     2 /* Time of system boot (in \fIut_tv\fP) */
Packit 7cfc04
#define NEW_TIME      3 /* Time after system clock change
Packit 7cfc04
                           (in \fIut_tv\fP) */
Packit 7cfc04
#define OLD_TIME      4 /* Time before system clock change
Packit 7cfc04
                           (in \fIut_tv\fP) */
Packit 7cfc04
#define INIT_PROCESS  5 /* Process spawned by \fBinit\fP(8) */
Packit 7cfc04
#define LOGIN_PROCESS 6 /* Session leader process for user login */
Packit 7cfc04
#define USER_PROCESS  7 /* Normal process */
Packit 7cfc04
#define DEAD_PROCESS  8 /* Terminated process */
Packit 7cfc04
#define ACCOUNTING    9 /* Not implemented */
Packit 7cfc04
Packit 7cfc04
#define UT_LINESIZE      32
Packit 7cfc04
#define UT_NAMESIZE      32
Packit 7cfc04
#define UT_HOSTSIZE     256
Packit 7cfc04
Packit 7cfc04
struct exit_status {              /* Type for ut_exit, below */
Packit 7cfc04
    short int e_termination;      /* Process termination status */
Packit 7cfc04
    short int e_exit;             /* Process exit status */
Packit 7cfc04
};
Packit 7cfc04
Packit 7cfc04
struct utmp {
Packit 7cfc04
    short   ut_type;              /* Type of record */
Packit 7cfc04
    pid_t   ut_pid;               /* PID of login process */
Packit 7cfc04
    char    ut_line[UT_LINESIZE]; /* Device name of tty \- "/dev/" */
Packit 7cfc04
    char    ut_id[4];             /* Terminal name suffix,
Packit 7cfc04
                                     or inittab(5) ID */
Packit 7cfc04
    char    ut_user[UT_NAMESIZE]; /* Username */
Packit 7cfc04
    char    ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or
Packit 7cfc04
                                     kernel version for run-level
Packit 7cfc04
                                     messages */
Packit 7cfc04
    struct  exit_status ut_exit;  /* Exit status of a process
Packit 7cfc04
                                     marked as DEAD_PROCESS; not
Packit 7cfc04
                                     used by Linux init (1 */
Packit 7cfc04
    /* The ut_session and ut_tv fields must be the same size when
Packit 7cfc04
       compiled 32- and 64-bit.  This allows data files and shared
Packit 7cfc04
       memory to be shared between 32- and 64-bit applications. */
Packit 7cfc04
#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
Packit 7cfc04
    int32_t ut_session;           /* Session ID (\fBgetsid\fP(2)),
Packit 7cfc04
                                     used for windowing */
Packit 7cfc04
    struct {
Packit 7cfc04
        int32_t tv_sec;           /* Seconds */
Packit 7cfc04
        int32_t tv_usec;          /* Microseconds */
Packit 7cfc04
    } ut_tv;                      /* Time entry was made */
Packit 7cfc04
#else
Packit 7cfc04
     long   ut_session;           /* Session ID */
Packit 7cfc04
     struct timeval ut_tv;        /* Time entry was made */
Packit 7cfc04
#endif
Packit 7cfc04
Packit 7cfc04
    int32_t ut_addr_v6[4];        /* Internet address of remote
Packit 7cfc04
                                     host; IPv4 address uses
Packit 7cfc04
                                     just ut_addr_v6[0] */
Packit 7cfc04
    char __unused[20];            /* Reserved for future use */
Packit 7cfc04
};
Packit 7cfc04
Packit 7cfc04
/* Backward compatibility hacks */
Packit 7cfc04
#define ut_name ut_user
Packit 7cfc04
#ifndef _NO_UT_TIME
Packit 7cfc04
#define ut_time ut_tv.tv_sec
Packit 7cfc04
#endif
Packit 7cfc04
#define ut_xtime ut_tv.tv_sec
Packit 7cfc04
#define ut_addr ut_addr_v6[0]
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
This structure gives the name of the special file associated with the
Packit 7cfc04
user's terminal, the user's login name, and the time of login in the form
Packit 7cfc04
of
Packit 7cfc04
.BR time (2).
Packit 7cfc04
String fields are terminated by a null byte (\(aq\e0\(aq)
Packit 7cfc04
if they are shorter than the size
Packit 7cfc04
of the field.
Packit 7cfc04
.PP
Packit 7cfc04
The first entries ever created result from
Packit 7cfc04
.BR init (1)
Packit 7cfc04
processing
Packit 7cfc04
.BR inittab (5).
Packit 7cfc04
Before an entry is processed, though,
Packit 7cfc04
.BR init (1)
Packit 7cfc04
cleans up utmp by setting \fIut_type\fP to \fBDEAD_PROCESS\fP, clearing
Packit 7cfc04
\fIut_user\fP, \fIut_host\fP, and \fIut_time\fP with null bytes for each
Packit 7cfc04
record which \fIut_type\fP is not \fBDEAD_PROCESS\fP or \fBRUN_LVL\fP
Packit 7cfc04
and where no process with PID \fIut_pid\fP exists.
Packit 7cfc04
If no empty record
Packit 7cfc04
with the needed \fIut_id\fP can be found,
Packit 7cfc04
.BR init (1)
Packit 7cfc04
creates a new one.
Packit 7cfc04
It sets \fIut_id\fP from the inittab, \fIut_pid\fP and \fIut_time\fP to the
Packit 7cfc04
current values, and \fIut_type\fP to \fBINIT_PROCESS\fP.
Packit 7cfc04
.PP
Packit 7cfc04
.BR mingetty (8)
Packit 7cfc04
(or
Packit 7cfc04
.BR agetty (8))
Packit 7cfc04
locates the entry by the PID, changes \fIut_type\fP to
Packit 7cfc04
\fBLOGIN_PROCESS\fP, changes \fIut_time\fP, sets \fIut_line\fP, and waits
Packit 7cfc04
for connection to be established.
Packit 7cfc04
.BR login (1),
Packit 7cfc04
after a user has been
Packit 7cfc04
authenticated, changes \fIut_type\fP to \fBUSER_PROCESS\fP, changes
Packit 7cfc04
\fIut_time\fP, and sets \fIut_host\fP and \fIut_addr\fP.
Packit 7cfc04
Depending on
Packit 7cfc04
.BR mingetty (8)
Packit 7cfc04
(or
Packit 7cfc04
.BR agetty (8))
Packit 7cfc04
and
Packit 7cfc04
.BR login (1),
Packit 7cfc04
records may be located by
Packit 7cfc04
\fIut_line\fP instead of the preferable \fIut_pid\fP.
Packit 7cfc04
.PP
Packit 7cfc04
When
Packit 7cfc04
.BR init (1)
Packit 7cfc04
finds that a process has exited, it locates its utmp
Packit 7cfc04
entry by \fIut_pid\fP, sets \fIut_type\fP to \fBDEAD_PROCESS\fP, and
Packit 7cfc04
clears \fIut_user\fP, \fIut_host\fP and \fIut_time\fP with null bytes.
Packit 7cfc04
.PP
Packit 7cfc04
.BR xterm (1)
Packit 7cfc04
and other terminal emulators directly create a
Packit 7cfc04
\fBUSER_PROCESS\fP record and generate the \fIut_id\fP by using the
Packit 7cfc04
string that suffix part of the terminal name (the characters
Packit 7cfc04
following \fI/dev/[pt]ty\fP).
Packit 7cfc04
If they find a \fBDEAD_PROCESS\fP for this ID,
Packit 7cfc04
they recycle it, otherwise they create a new entry.
Packit 7cfc04
If they can, they
Packit 7cfc04
will mark it as \fBDEAD_PROCESS\fP on exiting and it is advised that
Packit 7cfc04
they null \fIut_line\fP, \fIut_time\fP, \fIut_user\fP, and \fIut_host\fP
Packit 7cfc04
as well.
Packit 7cfc04
.PP
Packit 7cfc04
.BR telnetd (8)
Packit 7cfc04
sets up a \fBLOGIN_PROCESS\fP entry and leaves the rest to
Packit 7cfc04
.BR login (1)
Packit 7cfc04
as usual.
Packit 7cfc04
After the telnet session ends,
Packit 7cfc04
.BR telnetd (8)
Packit 7cfc04
cleans up utmp in the described way.
Packit 7cfc04
.PP
Packit 7cfc04
The \fIwtmp\fP file records all logins and logouts.
Packit 7cfc04
Its format is exactly like \fIutmp\fP except that a null username
Packit 7cfc04
indicates a logout
Packit 7cfc04
on the associated terminal.
Packit 7cfc04
Furthermore, the terminal name \fB~\fP
Packit 7cfc04
with username \fBshutdown\fP or \fBreboot\fP indicates a system
Packit 7cfc04
shutdown or reboot and the pair of terminal names \fB|\fP/\fB}\fP
Packit 7cfc04
logs the old/new system time when
Packit 7cfc04
.BR date (1)
Packit 7cfc04
changes it.
Packit 7cfc04
\fIwtmp\fP is maintained by
Packit 7cfc04
.BR login (1),
Packit 7cfc04
.BR init (1),
Packit 7cfc04
and some versions of
Packit 7cfc04
.BR getty (8)
Packit 7cfc04
(e.g.,
Packit 7cfc04
.BR mingetty (8)
Packit 7cfc04
or
Packit 7cfc04
.BR agetty (8)).
Packit 7cfc04
None of these programs creates the file, so if it is
Packit 7cfc04
removed, record-keeping is turned off.
Packit 7cfc04
.SH FILES
Packit 7cfc04
.I /var/run/utmp
Packit 7cfc04
.br
Packit 7cfc04
.I /var/log/wtmp
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.PP
Packit 7cfc04
POSIX.1 does not specify a
Packit 7cfc04
.I utmp
Packit 7cfc04
structure, but rather one named
Packit 7cfc04
.IR utmpx ,
Packit 7cfc04
with specifications for the fields
Packit 7cfc04
.IR ut_type ,
Packit 7cfc04
.IR ut_pid ,
Packit 7cfc04
.IR ut_line ,
Packit 7cfc04
.IR ut_id ,
Packit 7cfc04
.IR ut_user ,
Packit 7cfc04
and
Packit 7cfc04
.IR ut_tv .
Packit 7cfc04
POSIX.1 does not specify the lengths of the
Packit 7cfc04
.I ut_line
Packit 7cfc04
and
Packit 7cfc04
.I ut_user
Packit 7cfc04
fields.
Packit 7cfc04
.PP
Packit 7cfc04
Linux defines the
Packit 7cfc04
.I utmpx
Packit 7cfc04
structure to be the same as the
Packit 7cfc04
.I utmp
Packit 7cfc04
structure.
Packit 7cfc04
.SS Comparison with historical systems
Packit 7cfc04
Linux utmp entries conform neither to v7/BSD nor to System V; they are a
Packit 7cfc04
mix of the two.
Packit 7cfc04
.PP
Packit 7cfc04
v7/BSD has fewer fields; most importantly it lacks
Packit 7cfc04
\fIut_type\fP, which causes native v7/BSD-like programs to display (for
Packit 7cfc04
example) dead or login entries.
Packit 7cfc04
Further, there is no configuration file
Packit 7cfc04
which allocates slots to sessions.
Packit 7cfc04
BSD does so because it lacks \fIut_id\fP fields.
Packit 7cfc04
.PP
Packit 7cfc04
In Linux (as in System V), the \fIut_id\fP field of a
Packit 7cfc04
record will never change once it has been set, which reserves that slot
Packit 7cfc04
without needing a configuration file.
Packit 7cfc04
Clearing \fIut_id\fP may result
Packit 7cfc04
in race conditions leading to corrupted utmp entries and potential
Packit 7cfc04
security holes.
Packit 7cfc04
Clearing the abovementioned fields by filling them
Packit 7cfc04
with null bytes is not required by System V semantics,
Packit 7cfc04
but makes it possible to run
Packit 7cfc04
many programs which assume BSD semantics and which do not modify utmp.
Packit 7cfc04
Linux uses the BSD conventions for line contents, as documented above.
Packit 7cfc04
.PP
Packit 7cfc04
.\" mtk: What is the referrent of "them" in the following sentence?
Packit 7cfc04
.\" System V only uses the type field to mark them and logs
Packit 7cfc04
.\" informative messages such as \fB"new time"\fP in the line field.
Packit 7cfc04
System V has no \fIut_host\fP or \fIut_addr_v6\fP fields.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
.PP
Packit 7cfc04
Unlike various other
Packit 7cfc04
systems, where utmp logging can be disabled by removing the file, utmp
Packit 7cfc04
must always exist on Linux.
Packit 7cfc04
If you want to disable
Packit 7cfc04
.BR who (1),
Packit 7cfc04
then do not make utmp world readable.
Packit 7cfc04
.PP
Packit 7cfc04
The file format is machine-dependent, so it is recommended that it be
Packit 7cfc04
processed only on the machine architecture where it was created.
Packit 7cfc04
.PP
Packit 7cfc04
Note that on \fIbiarch\fP platforms, that is, systems which can run both
Packit 7cfc04
32-bit and 64-bit applications (x86-64, ppc64, s390x, etc.),
Packit 7cfc04
\fIut_tv\fP is the same size in 32-bit mode as in 64-bit mode.
Packit 7cfc04
The same goes for \fIut_session\fP and \fIut_time\fP if they are present.
Packit 7cfc04
This allows data files and shared memory to be shared between
Packit 7cfc04
32-bit and 64-bit applications.
Packit 7cfc04
This is achieved by changing the type of
Packit 7cfc04
.I ut_session
Packit 7cfc04
to
Packit 7cfc04
.IR int32_t ,
Packit 7cfc04
and that of
Packit 7cfc04
.I ut_tv
Packit 7cfc04
to a struct with two
Packit 7cfc04
.I int32_t
Packit 7cfc04
fields
Packit 7cfc04
.I tv_sec
Packit 7cfc04
and
Packit 7cfc04
.IR tv_usec .
Packit 7cfc04
Since \fIut_tv\fP may not be the same as \fIstruct timeval\fP,
Packit 7cfc04
then instead of the call:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
gettimeofday((struct timeval *) &ut.ut_tv, NULL);
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
the following method of setting this field is recommended:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct utmp ut;
Packit 7cfc04
struct timeval tv;
Packit 7cfc04
Packit 7cfc04
gettimeofday(&tv, NULL);
Packit 7cfc04
ut.ut_tv.tv_sec = tv.tv_sec;
Packit 7cfc04
ut.ut_tv.tv_usec = tv.tv_usec;
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.\" .PP
Packit 7cfc04
.\" Note that the \fIutmp\fP struct from libc5 has changed in libc6.
Packit 7cfc04
.\" Because of this,
Packit 7cfc04
.\" binaries using the old libc5 struct will corrupt
Packit 7cfc04
.\" .IR /var/run/utmp " and/or " /var/log/wtmp .
Packit 7cfc04
.\" .SH BUGS
Packit 7cfc04
.\" This man page is based on the libc5 one, things may work differently now.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR ac (1),
Packit 7cfc04
.BR date (1),
Packit 7cfc04
.BR init (1),
Packit 7cfc04
.BR last (1),
Packit 7cfc04
.BR login (1),
Packit 7cfc04
.BR logname (1),
Packit 7cfc04
.BR lslogins (1),
Packit 7cfc04
.BR users (1),
Packit 7cfc04
.BR utmpdump (1),
Packit 7cfc04
.BR who (1),
Packit 7cfc04
.BR getutent (3),
Packit 7cfc04
.BR getutmp (3),
Packit 7cfc04
.BR login (3),
Packit 7cfc04
.BR logout (3),
Packit 7cfc04
.BR logwtmp (3),
Packit 7cfc04
.BR updwtmp (3)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.