473 lines
17 KiB
HTML
473 lines
17 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of UTMP</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>UTMP</H1>
|
|
Section: Linux Programmer's Manual (5)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
utmp, wtmp - login records
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/utmp.h">utmp.h</A>></B>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<I>utmp</I>
|
|
|
|
file allows one to discover information about who is currently using the
|
|
system.
|
|
There may be more users currently using the system, because not
|
|
all programs use utmp logging.
|
|
<P>
|
|
|
|
<B>Warning:</B>
|
|
|
|
<I>utmp</I>
|
|
|
|
must not be writable by the user class "other",
|
|
because many system programs (foolishly)
|
|
depend on its integrity.
|
|
You risk faked system logfiles and
|
|
modifications of system files if you leave
|
|
<I>utmp</I>
|
|
|
|
writable to any user other than the owner and group owner of the file.
|
|
<P>
|
|
|
|
The file is a sequence of
|
|
<I>utmp</I>
|
|
|
|
structures,
|
|
declared as follows in
|
|
<I><<A HREF="file:///usr/include/utmp.h">utmp.h</A>></I>
|
|
|
|
(note that this is only one of several definitions
|
|
around; details depend on the version of libc):
|
|
<P>
|
|
|
|
|
|
|
|
/* Values for ut_type field, below */
|
|
<P>
|
|
#define EMPTY 0 /* Record does not contain valid info
|
|
<BR> (formerly known as UT_UNKNOWN on Linux) */
|
|
#define RUN_LVL 1 /* Change in system run-level (see
|
|
<BR> <B><A HREF="/cgi-bin/man/man2html?8+init">init</A></B>(8)) */
|
|
#define BOOT_TIME 2 /* Time of system boot (in <I>ut_tv</I>) */
|
|
#define NEW_TIME 3 /* Time after system clock change
|
|
<BR> (in <I>ut_tv</I>) */
|
|
#define OLD_TIME 4 /* Time before system clock change
|
|
<BR> (in <I>ut_tv</I>) */
|
|
#define INIT_PROCESS 5 /* Process spawned by <B><A HREF="/cgi-bin/man/man2html?8+init">init</A></B>(8) */
|
|
#define LOGIN_PROCESS 6 /* Session leader process for user login */
|
|
#define USER_PROCESS 7 /* Normal process */
|
|
#define DEAD_PROCESS 8 /* Terminated process */
|
|
#define ACCOUNTING 9 /* Not implemented */
|
|
<P>
|
|
#define UT_LINESIZE 32
|
|
#define UT_NAMESIZE 32
|
|
#define UT_HOSTSIZE 256
|
|
<P>
|
|
struct exit_status { /* Type for ut_exit, below */
|
|
<BR> short int e_termination; /* Process termination status */
|
|
<BR> short int e_exit; /* Process exit status */
|
|
};
|
|
<P>
|
|
struct utmp {
|
|
<BR> short ut_type; /* Type of record */
|
|
<BR> pid_t ut_pid; /* PID of login process */
|
|
<BR> char ut_line[UT_LINESIZE]; /* Device name of tty - "/dev/" */
|
|
<BR> char ut_id[4]; /* Terminal name suffix,
|
|
<BR> or <A HREF="/cgi-bin/man/man2html?5+inittab">inittab</A>(5) ID */
|
|
<BR> char ut_user[UT_NAMESIZE]; /* Username */
|
|
<BR> char ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or
|
|
<BR> kernel version for run-level
|
|
<BR> messages */
|
|
<BR> struct exit_status ut_exit; /* Exit status of a process
|
|
<BR> marked as DEAD_PROCESS; not
|
|
<BR> used by Linux init (1 */
|
|
<BR> /* The ut_session and ut_tv fields must be the same size when
|
|
<BR> compiled 32- and 64-bit. This allows data files and shared
|
|
<BR> memory to be shared between 32- and 64-bit applications. */
|
|
#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
|
|
<BR> int32_t ut_session; /* Session ID (<B><A HREF="/cgi-bin/man/man2html?2+getsid">getsid</A></B>(2)),
|
|
<BR> used for windowing */
|
|
<BR> struct {
|
|
<BR> int32_t tv_sec; /* Seconds */
|
|
<BR> int32_t tv_usec; /* Microseconds */
|
|
<BR> } ut_tv; /* Time entry was made */
|
|
#else
|
|
<BR> long ut_session; /* Session ID */
|
|
<BR> struct timeval ut_tv; /* Time entry was made */
|
|
#endif
|
|
<P>
|
|
<BR> int32_t ut_addr_v6[4]; /* Internet address of remote
|
|
<BR> host; IPv4 address uses
|
|
<BR> just ut_addr_v6[0] */
|
|
<BR> char __unused[20]; /* Reserved for future use */
|
|
};
|
|
<P>
|
|
/* Backward compatibility hacks */
|
|
#define ut_name ut_user
|
|
#ifndef _NO_UT_TIME
|
|
#define ut_time ut_tv.tv_sec
|
|
#endif
|
|
#define ut_xtime ut_tv.tv_sec
|
|
#define ut_addr ut_addr_v6[0]
|
|
|
|
|
|
<P>
|
|
|
|
This structure gives the name of the special file associated with the
|
|
user's terminal, the user's login name, and the time of login in the form
|
|
of
|
|
<B><A HREF="/cgi-bin/man/man2html?2+time">time</A></B>(2).
|
|
|
|
String fields are terminated by a null byte ('\0')
|
|
if they are shorter than the size
|
|
of the field.
|
|
<P>
|
|
|
|
The first entries ever created result from
|
|
<B><A HREF="/cgi-bin/man/man2html?1+init">init</A></B>(1)
|
|
|
|
processing
|
|
<B><A HREF="/cgi-bin/man/man2html?5+inittab">inittab</A></B>(5).
|
|
|
|
Before an entry is processed, though,
|
|
<B><A HREF="/cgi-bin/man/man2html?1+init">init</A></B>(1)
|
|
|
|
cleans up utmp by setting <I>ut_type</I> to <B>DEAD_PROCESS</B>, clearing
|
|
<I>ut_user</I>, <I>ut_host</I>, and <I>ut_time</I> with null bytes for each
|
|
record which <I>ut_type</I> is not <B>DEAD_PROCESS</B> or <B>RUN_LVL</B>
|
|
and where no process with PID <I>ut_pid</I> exists.
|
|
If no empty record
|
|
with the needed <I>ut_id</I> can be found,
|
|
<B><A HREF="/cgi-bin/man/man2html?1+init">init</A></B>(1)
|
|
|
|
creates a new one.
|
|
It sets <I>ut_id</I> from the inittab, <I>ut_pid</I> and <I>ut_time</I> to the
|
|
current values, and <I>ut_type</I> to <B>INIT_PROCESS</B>.
|
|
<P>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+mingetty">mingetty</A></B>(8)
|
|
|
|
(or
|
|
<B><A HREF="/cgi-bin/man/man2html?8+agetty">agetty</A></B>(8))
|
|
|
|
locates the entry by the PID, changes <I>ut_type</I> to
|
|
<B>LOGIN_PROCESS</B>, changes <I>ut_time</I>, sets <I>ut_line</I>, and waits
|
|
for connection to be established.
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1),
|
|
|
|
after a user has been
|
|
authenticated, changes <I>ut_type</I> to <B>USER_PROCESS</B>, changes
|
|
<I>ut_time</I>, and sets <I>ut_host</I> and <I>ut_addr</I>.
|
|
Depending on
|
|
<B><A HREF="/cgi-bin/man/man2html?8+mingetty">mingetty</A></B>(8)
|
|
|
|
(or
|
|
<B><A HREF="/cgi-bin/man/man2html?8+agetty">agetty</A></B>(8))
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1),
|
|
|
|
records may be located by
|
|
<I>ut_line</I> instead of the preferable <I>ut_pid</I>.
|
|
<P>
|
|
|
|
When
|
|
<B><A HREF="/cgi-bin/man/man2html?1+init">init</A></B>(1)
|
|
|
|
finds that a process has exited, it locates its utmp
|
|
entry by <I>ut_pid</I>, sets <I>ut_type</I> to <B>DEAD_PROCESS</B>, and
|
|
clears <I>ut_user</I>, <I>ut_host</I> and <I>ut_time</I> with null bytes.
|
|
<P>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+xterm">xterm</A></B>(1)
|
|
|
|
and other terminal emulators directly create a
|
|
<B>USER_PROCESS</B> record and generate the <I>ut_id</I> by using the
|
|
string that suffix part of the terminal name (the characters
|
|
following <I>/dev/[pt]ty</I>).
|
|
If they find a <B>DEAD_PROCESS</B> for this ID,
|
|
they recycle it, otherwise they create a new entry.
|
|
If they can, they
|
|
will mark it as <B>DEAD_PROCESS</B> on exiting and it is advised that
|
|
they null <I>ut_line</I>, <I>ut_time</I>, <I>ut_user</I>, and <I>ut_host</I>
|
|
as well.
|
|
<P>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+telnetd">telnetd</A></B>(8)
|
|
|
|
sets up a <B>LOGIN_PROCESS</B> entry and leaves the rest to
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1)
|
|
|
|
as usual.
|
|
After the telnet session ends,
|
|
<B><A HREF="/cgi-bin/man/man2html?8+telnetd">telnetd</A></B>(8)
|
|
|
|
cleans up utmp in the described way.
|
|
<P>
|
|
|
|
The <I>wtmp</I> file records all logins and logouts.
|
|
Its format is exactly like <I>utmp</I> except that a null username
|
|
indicates a logout
|
|
on the associated terminal.
|
|
Furthermore, the terminal name <B>~</B>
|
|
with username <B>shutdown</B> or <B>reboot</B> indicates a system
|
|
shutdown or reboot and the pair of terminal names <B>|</B>/<B>}</B>
|
|
logs the old/new system time when
|
|
<B><A HREF="/cgi-bin/man/man2html?1+date">date</A></B>(1)
|
|
|
|
changes it.
|
|
<I>wtmp</I> is maintained by
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+init">init</A></B>(1),
|
|
|
|
and some versions of
|
|
<B><A HREF="/cgi-bin/man/man2html?8+getty">getty</A></B>(8)
|
|
|
|
(e.g.,
|
|
<B><A HREF="/cgi-bin/man/man2html?8+mingetty">mingetty</A></B>(8)
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?8+agetty">agetty</A></B>(8)).
|
|
|
|
None of these programs creates the file, so if it is
|
|
removed, record-keeping is turned off.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>FILES</H2>
|
|
|
|
<I>/var/run/utmp</I>
|
|
|
|
<BR>
|
|
|
|
<I>/var/log/wtmp</I>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
<P>
|
|
|
|
POSIX.1 does not specify a
|
|
<I>utmp</I>
|
|
|
|
structure, but rather one named
|
|
<I>utmpx</I>,
|
|
|
|
with specifications for the fields
|
|
<I>ut_type</I>,
|
|
|
|
<I>ut_pid</I>,
|
|
|
|
<I>ut_line</I>,
|
|
|
|
<I>ut_id</I>,
|
|
|
|
<I>ut_user</I>,
|
|
|
|
and
|
|
<I>ut_tv</I>.
|
|
|
|
POSIX.1 does not specify the lengths of the
|
|
<I>ut_line</I>
|
|
|
|
and
|
|
<I>ut_user</I>
|
|
|
|
fields.
|
|
<P>
|
|
|
|
Linux defines the
|
|
<I>utmpx</I>
|
|
|
|
structure to be the same as the
|
|
<I>utmp</I>
|
|
|
|
structure.
|
|
<A NAME="lbAG"> </A>
|
|
<H3>Comparison with historical systems</H3>
|
|
|
|
Linux utmp entries conform neither to v7/BSD nor to System V; they are a
|
|
mix of the two.
|
|
<P>
|
|
|
|
v7/BSD has fewer fields; most importantly it lacks
|
|
<I>ut_type</I>, which causes native v7/BSD-like programs to display (for
|
|
example) dead or login entries.
|
|
Further, there is no configuration file
|
|
which allocates slots to sessions.
|
|
BSD does so because it lacks <I>ut_id</I> fields.
|
|
<P>
|
|
|
|
In Linux (as in System V), the <I>ut_id</I> field of a
|
|
record will never change once it has been set, which reserves that slot
|
|
without needing a configuration file.
|
|
Clearing <I>ut_id</I> may result
|
|
in race conditions leading to corrupted utmp entries and potential
|
|
security holes.
|
|
Clearing the abovementioned fields by filling them
|
|
with null bytes is not required by System V semantics,
|
|
but makes it possible to run
|
|
many programs which assume BSD semantics and which do not modify utmp.
|
|
Linux uses the BSD conventions for line contents, as documented above.
|
|
<P>
|
|
|
|
|
|
|
|
|
|
System V has no <I>ut_host</I> or <I>ut_addr_v6</I> fields.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
<P>
|
|
|
|
Unlike various other
|
|
systems, where utmp logging can be disabled by removing the file, utmp
|
|
must always exist on Linux.
|
|
If you want to disable
|
|
<B><A HREF="/cgi-bin/man/man2html?1+who">who</A></B>(1),
|
|
|
|
then do not make utmp world readable.
|
|
<P>
|
|
|
|
The file format is machine-dependent, so it is recommended that it be
|
|
processed only on the machine architecture where it was created.
|
|
<P>
|
|
|
|
Note that on <I>biarch</I> platforms, that is, systems which can run both
|
|
32-bit and 64-bit applications (x86-64, ppc64, s390x, etc.),
|
|
<I>ut_tv</I> is the same size in 32-bit mode as in 64-bit mode.
|
|
The same goes for <I>ut_session</I> and <I>ut_time</I> if they are present.
|
|
This allows data files and shared memory to be shared between
|
|
32-bit and 64-bit applications.
|
|
This is achieved by changing the type of
|
|
<I>ut_session</I>
|
|
|
|
to
|
|
<I>int32_t</I>,
|
|
|
|
and that of
|
|
<I>ut_tv</I>
|
|
|
|
to a struct with two
|
|
<I>int32_t</I>
|
|
|
|
fields
|
|
<I>tv_sec</I>
|
|
|
|
and
|
|
<I>tv_usec</I>.
|
|
|
|
Since <I>ut_tv</I> may not be the same as <I>struct timeval</I>,
|
|
then instead of the call:
|
|
<P>
|
|
|
|
|
|
|
|
gettimeofday((struct timeval *) &ut.ut_tv, NULL);
|
|
|
|
|
|
<P>
|
|
|
|
the following method of setting this field is recommended:
|
|
<P>
|
|
|
|
|
|
|
|
struct utmp ut;
|
|
struct timeval tv;
|
|
<P>
|
|
gettimeofday(&tv, NULL);
|
|
ut.ut_tv.tv_sec = tv.tv_sec;
|
|
ut.ut_tv.tv_usec = tv.tv_usec;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+ac">ac</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+date">date</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+init">init</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+last">last</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+logname">logname</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+lslogins">lslogins</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+users">users</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+utmpdump">utmpdump</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+who">who</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getutent">getutent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getutmp">getutmp</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+login">login</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+logout">logout</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+logwtmp">logwtmp</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+updwtmp">updwtmp</A></B>(3)
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">FILES</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">CONFORMING TO</A><DD>
|
|
<DL>
|
|
<DT id="6"><A HREF="#lbAG">Comparison with historical systems</A><DD>
|
|
</DL>
|
|
<DT id="7"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="9"><A HREF="#lbAJ">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:06:06 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|