man-pages/man5/utmp.5.html
2021-03-31 01:06:50 +01:00

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">&nbsp;</A>
<H2>NAME</H2>
utmp, wtmp - login records
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/utmp.h">utmp.h</A>&gt;</B>
<A NAME="lbAD">&nbsp;</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 &quot;other&quot;,
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>&lt;<A HREF="file:///usr/include/utmp.h">utmp.h</A>&gt;</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(formerly&nbsp;known&nbsp;as&nbsp;UT_UNKNOWN&nbsp;on&nbsp;Linux)&nbsp;*/
#define RUN_LVL 1 /* Change in system run-level (see
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B><A HREF="/cgi-bin/man/man2html?8+init">init</A></B>(8))&nbsp;*/
#define BOOT_TIME 2 /* Time of system boot (in <I>ut_tv</I>) */
#define NEW_TIME 3 /* Time after system clock change
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(in&nbsp;<I>ut_tv</I>)&nbsp;*/
#define OLD_TIME 4 /* Time before system clock change
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(in&nbsp;<I>ut_tv</I>)&nbsp;*/
#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>&nbsp;&nbsp;&nbsp;&nbsp;short&nbsp;int&nbsp;e_termination;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Process&nbsp;termination&nbsp;status&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;short&nbsp;int&nbsp;e_exit;&nbsp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gi-bin/man/man2html?5+inittab">inittab</A>(5)&nbsp;ID&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;&nbsp;&nbsp;ut_user[UT_NAMESIZE];&nbsp;/*&nbsp;Username&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;&nbsp;&nbsp;ut_host[UT_HOSTSIZE];&nbsp;/*&nbsp;Hostname&nbsp;for&nbsp;remote&nbsp;login,&nbsp;or
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kernel&nbsp;version&nbsp;for&nbsp;run-level
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;struct&nbsp;&nbsp;exit_status&nbsp;ut_exit;&nbsp;&nbsp;/*&nbsp;Exit&nbsp;status&nbsp;of&nbsp;a&nbsp;process
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;marked&nbsp;as&nbsp;DEAD_PROCESS;&nbsp;not
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used&nbsp;by&nbsp;Linux&nbsp;init&nbsp;(1&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;The&nbsp;ut_session&nbsp;and&nbsp;ut_tv&nbsp;fields&nbsp;must&nbsp;be&nbsp;the&nbsp;same&nbsp;size&nbsp;when
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compiled&nbsp;32-&nbsp;and&nbsp;64-bit.&nbsp;&nbsp;This&nbsp;allows&nbsp;data&nbsp;files&nbsp;and&nbsp;shared
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory&nbsp;to&nbsp;be&nbsp;shared&nbsp;between&nbsp;32-&nbsp;and&nbsp;64-bit&nbsp;applications.&nbsp;*/
#if __WORDSIZE == 64 &amp;&amp; defined __WORDSIZE_COMPAT32
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int32_t&nbsp;ut_session;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Session&nbsp;ID&nbsp;(<B><A HREF="/cgi-bin/man/man2html?2+getsid">getsid</A></B>(2)),
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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if
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int32_t&nbsp;ut_addr_v6[4];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Internet&nbsp;address&nbsp;of&nbsp;remote
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host;&nbsp;IPv4&nbsp;address&nbsp;uses
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;just&nbsp;ut_addr_v6[0]&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;__unused[20];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Reserved&nbsp;for&nbsp;future&nbsp;use&nbsp;*/
};
<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">&nbsp;</A>
<H2>FILES</H2>
<I>/var/run/utmp</I>
<BR>
<I>/var/log/wtmp</I>
<A NAME="lbAF">&nbsp;</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">&nbsp;</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">&nbsp;</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 *) &amp;ut.ut_tv, NULL);
<P>
the following method of setting this field is recommended:
<P>
struct utmp ut;
struct timeval tv;
<P>
gettimeofday(&amp;tv, NULL);
ut.ut_tv.tv_sec = tv.tv_sec;
ut.ut_tv.tv_usec = tv.tv_usec;
<A NAME="lbAI">&nbsp;</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">&nbsp;</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">&nbsp;</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>