| 1 |
.\" Copyright (c) 1993 Michael Haardt ([email protected]), |
| 2 |
.\" Fri Apr 2 11:32:09 MET DST 1993 |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
.\" |
| 6 |
.\" Modified 1993-07-25 by Rik Faith ([email protected]) |
| 7 |
.\" Modified 1995-02-26 by Michael Haardt |
| 8 |
.\" Modified 1996-07-20 by Michael Haardt |
| 9 |
.\" Modified 1997-07-02 by Nicolás Lichtmaier <[email protected]> |
| 10 |
.\" Modified 2004-10-31 by aeb, following Gwenole Beauchesne |
| 11 |
.TH utmp 5 2024-06-15 "Linux man-pages 6.9.1" |
| 12 |
.SH NAME |
| 13 |
utmp, wtmp \- login records |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
.B #include <utmp.h> |
| 17 |
.fi |
| 18 |
.SH DESCRIPTION |
| 19 |
The |
| 20 |
.I utmp |
| 21 |
file allows one to discover information about who is currently using the |
| 22 |
system. |
| 23 |
There may be more users currently using the system, because not |
| 24 |
all programs use utmp logging. |
| 25 |
.P |
| 26 |
.B Warning: |
| 27 |
.I utmp |
| 28 |
must not be writable by the user class "other", |
| 29 |
because many system programs (foolishly) |
| 30 |
depend on its integrity. |
| 31 |
You risk faked system logfiles and |
| 32 |
modifications of system files if you leave |
| 33 |
.I utmp |
| 34 |
writable to any user other than the owner and group owner of the file. |
| 35 |
.P |
| 36 |
The file is a sequence of |
| 37 |
.I utmp |
| 38 |
structures, |
| 39 |
declared as follows in |
| 40 |
.I <utmp.h> |
| 41 |
(note that this is only one of several definitions |
| 42 |
around; details depend on the version of libc): |
| 43 |
.P |
| 44 |
.in +4n |
| 45 |
.EX |
| 46 |
/* Values for ut_type field, below */ |
| 47 |
\& |
| 48 |
#define EMPTY 0 /* Record does not contain valid info |
| 49 |
(formerly known as UT_UNKNOWN on Linux) */ |
| 50 |
#define RUN_LVL 1 /* Change in system run\-level (see |
| 51 |
\fBinit\fP(1)) */ |
| 52 |
#define BOOT_TIME 2 /* Time of system boot (in \fIut_tv\fP) */ |
| 53 |
#define NEW_TIME 3 /* Time after system clock change |
| 54 |
(in \fIut_tv\fP) */ |
| 55 |
#define OLD_TIME 4 /* Time before system clock change |
| 56 |
(in \fIut_tv\fP) */ |
| 57 |
#define INIT_PROCESS 5 /* Process spawned by \fBinit\fP(1) */ |
| 58 |
#define LOGIN_PROCESS 6 /* Session leader process for user login */ |
| 59 |
#define USER_PROCESS 7 /* Normal process */ |
| 60 |
#define DEAD_PROCESS 8 /* Terminated process */ |
| 61 |
#define ACCOUNTING 9 /* Not implemented */ |
| 62 |
\& |
| 63 |
#define UT_LINESIZE 32 |
| 64 |
#define UT_NAMESIZE 32 |
| 65 |
#define UT_HOSTSIZE 256 |
| 66 |
\& |
| 67 |
struct exit_status { /* Type for ut_exit, below */ |
| 68 |
short e_termination; /* Process termination status */ |
| 69 |
short e_exit; /* Process exit status */ |
| 70 |
}; |
| 71 |
\& |
| 72 |
struct utmp { |
| 73 |
short ut_type; /* Type of record */ |
| 74 |
pid_t ut_pid; /* PID of login process */ |
| 75 |
char ut_line[UT_LINESIZE]; /* Device name of tty \- "/dev/" */ |
| 76 |
char ut_id[4]; /* Terminal name suffix, |
| 77 |
or inittab(5) ID */ |
| 78 |
char ut_user[UT_NAMESIZE]; /* Username */ |
| 79 |
char ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or |
| 80 |
kernel version for run\-level |
| 81 |
messages */ |
| 82 |
struct exit_status ut_exit; /* Exit status of a process |
| 83 |
marked as DEAD_PROCESS; not |
| 84 |
used by Linux init(1) */ |
| 85 |
/* The ut_session and ut_tv fields must be the same size when |
| 86 |
compiled 32\- and 64\-bit. This allows data files and shared |
| 87 |
memory to be shared between 32\- and 64\-bit applications. */ |
| 88 |
#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 |
| 89 |
int32_t ut_session; /* Session ID (\fBgetsid\fP(2)), |
| 90 |
used for windowing */ |
| 91 |
struct { |
| 92 |
int32_t tv_sec; /* Seconds */ |
| 93 |
int32_t tv_usec; /* Microseconds */ |
| 94 |
} ut_tv; /* Time entry was made */ |
| 95 |
#else |
| 96 |
long ut_session; /* Session ID */ |
| 97 |
struct timeval ut_tv; /* Time entry was made */ |
| 98 |
#endif |
| 99 |
\& |
| 100 |
int32_t ut_addr_v6[4]; /* Internet address of remote |
| 101 |
host; IPv4 address uses |
| 102 |
just ut_addr_v6[0] */ |
| 103 |
char __unused[20]; /* Reserved for future use */ |
| 104 |
}; |
| 105 |
\& |
| 106 |
/* Backward compatibility hacks */ |
| 107 |
#define ut_name ut_user |
| 108 |
#ifndef _NO_UT_TIME |
| 109 |
#define ut_time ut_tv.tv_sec |
| 110 |
#endif |
| 111 |
#define ut_xtime ut_tv.tv_sec |
| 112 |
#define ut_addr ut_addr_v6[0] |
| 113 |
.EE |
| 114 |
.in |
| 115 |
.P |
| 116 |
This structure gives the name of the special file associated with the |
| 117 |
user's terminal, the user's login name, and the time of login in the form |
| 118 |
of |
| 119 |
.BR time (2). |
| 120 |
String fields are terminated by a null byte (\[aq]\[rs]0\[aq]) |
| 121 |
if they are shorter than the size |
| 122 |
of the field. |
| 123 |
.P |
| 124 |
The first entries ever created result from |
| 125 |
.BR init (1) |
| 126 |
processing |
| 127 |
.BR inittab (5). |
| 128 |
Before an entry is processed, though, |
| 129 |
.BR init (1) |
| 130 |
cleans up utmp by setting \fIut_type\fP to \fBDEAD_PROCESS\fP, clearing |
| 131 |
\fIut_user\fP, \fIut_host\fP, and \fIut_time\fP with null bytes for each |
| 132 |
record which \fIut_type\fP is not \fBDEAD_PROCESS\fP or \fBRUN_LVL\fP |
| 133 |
and where no process with PID \fIut_pid\fP exists. |
| 134 |
If no empty record |
| 135 |
with the needed \fIut_id\fP can be found, |
| 136 |
.BR init (1) |
| 137 |
creates a new one. |
| 138 |
It sets \fIut_id\fP from the inittab, \fIut_pid\fP and \fIut_time\fP to the |
| 139 |
current values, and \fIut_type\fP to \fBINIT_PROCESS\fP. |
| 140 |
.P |
| 141 |
.BR mingetty (8) |
| 142 |
(or |
| 143 |
.BR agetty (8)) |
| 144 |
locates the entry by the PID, changes \fIut_type\fP to |
| 145 |
\fBLOGIN_PROCESS\fP, changes \fIut_time\fP, sets \fIut_line\fP, and waits |
| 146 |
for connection to be established. |
| 147 |
.BR login (1), |
| 148 |
after a user has been |
| 149 |
authenticated, changes \fIut_type\fP to \fBUSER_PROCESS\fP, changes |
| 150 |
\fIut_time\fP, and sets \fIut_host\fP and \fIut_addr\fP. |
| 151 |
Depending on |
| 152 |
.BR mingetty (8) |
| 153 |
(or |
| 154 |
.BR agetty (8)) |
| 155 |
and |
| 156 |
.BR login (1), |
| 157 |
records may be located by |
| 158 |
\fIut_line\fP instead of the preferable \fIut_pid\fP. |
| 159 |
.P |
| 160 |
When |
| 161 |
.BR init (1) |
| 162 |
finds that a process has exited, it locates its utmp entry by |
| 163 |
.IR ut_pid , |
| 164 |
sets |
| 165 |
.I ut_type |
| 166 |
to |
| 167 |
.BR DEAD_PROCESS , |
| 168 |
and clears |
| 169 |
.IR ut_user , |
| 170 |
.IR ut_host , |
| 171 |
and |
| 172 |
.I ut_time |
| 173 |
with null bytes. |
| 174 |
.P |
| 175 |
.BR xterm (1) |
| 176 |
and other terminal emulators directly create a |
| 177 |
\fBUSER_PROCESS\fP record and generate the \fIut_id\fP by using the |
| 178 |
string that suffix part of the terminal name (the characters |
| 179 |
following |
| 180 |
.IR /dev/ [pt] ty ). |
| 181 |
If they find a \fBDEAD_PROCESS\fP for this ID, |
| 182 |
they recycle it, otherwise they create a new entry. |
| 183 |
If they can, they |
| 184 |
will mark it as \fBDEAD_PROCESS\fP on exiting and it is advised that |
| 185 |
they null \fIut_line\fP, \fIut_time\fP, \fIut_user\fP, and \fIut_host\fP |
| 186 |
as well. |
| 187 |
.P |
| 188 |
.BR telnetd (8) |
| 189 |
sets up a \fBLOGIN_PROCESS\fP entry and leaves the rest to |
| 190 |
.BR login (1) |
| 191 |
as usual. |
| 192 |
After the telnet session ends, |
| 193 |
.BR telnetd (8) |
| 194 |
cleans up utmp in the described way. |
| 195 |
.P |
| 196 |
The \fIwtmp\fP file records all logins and logouts. |
| 197 |
Its format is exactly like \fIutmp\fP except that a null username |
| 198 |
indicates a logout |
| 199 |
on the associated terminal. |
| 200 |
Furthermore, the terminal name \fB\[ti]\fP |
| 201 |
with username \fBshutdown\fP or \fBreboot\fP indicates a system |
| 202 |
shutdown or reboot and the pair of terminal names \fB|\fP/\fB}\fP |
| 203 |
logs the old/new system time when |
| 204 |
.BR date (1) |
| 205 |
changes it. |
| 206 |
\fIwtmp\fP is maintained by |
| 207 |
.BR login (1), |
| 208 |
.BR init (1), |
| 209 |
and some versions of |
| 210 |
.BR getty (8) |
| 211 |
(e.g., |
| 212 |
.BR mingetty (8) |
| 213 |
or |
| 214 |
.BR agetty (8)). |
| 215 |
None of these programs creates the file, so if it is |
| 216 |
removed, record-keeping is turned off. |
| 217 |
.SH FILES |
| 218 |
.I /var/run/utmp |
| 219 |
.br |
| 220 |
.I /var/log/wtmp |
| 221 |
.SH VERSIONS |
| 222 |
POSIX.1 does not specify a |
| 223 |
.I utmp |
| 224 |
structure, but rather one named |
| 225 |
.I utmpx |
| 226 |
(as part of the XSI extension), |
| 227 |
with specifications for the fields |
| 228 |
.IR ut_type , |
| 229 |
.IR ut_pid , |
| 230 |
.IR ut_line , |
| 231 |
.IR ut_id , |
| 232 |
.IR ut_user , |
| 233 |
and |
| 234 |
.IR ut_tv . |
| 235 |
POSIX.1 does not specify the lengths of the |
| 236 |
.I ut_line |
| 237 |
and |
| 238 |
.I ut_user |
| 239 |
fields. |
| 240 |
.P |
| 241 |
Linux defines the |
| 242 |
.I utmpx |
| 243 |
structure to be the same as the |
| 244 |
.I utmp |
| 245 |
structure. |
| 246 |
.SH STANDARDS |
| 247 |
Linux. |
| 248 |
.SH HISTORY |
| 249 |
Linux utmp entries conform neither to v7/BSD nor to System V; they are a |
| 250 |
mix of the two. |
| 251 |
.P |
| 252 |
v7/BSD has fewer fields; most importantly it lacks |
| 253 |
\fIut_type\fP, which causes native v7/BSD-like programs to display (for |
| 254 |
example) dead or login entries. |
| 255 |
Further, there is no configuration file |
| 256 |
which allocates slots to sessions. |
| 257 |
BSD does so because it lacks \fIut_id\fP fields. |
| 258 |
.P |
| 259 |
In Linux (as in System V), the \fIut_id\fP field of a |
| 260 |
record will never change once it has been set, which reserves that slot |
| 261 |
without needing a configuration file. |
| 262 |
Clearing \fIut_id\fP may result |
| 263 |
in race conditions leading to corrupted utmp entries and potential |
| 264 |
security holes. |
| 265 |
Clearing the abovementioned fields by filling them |
| 266 |
with null bytes is not required by System V semantics, |
| 267 |
but makes it possible to run |
| 268 |
many programs which assume BSD semantics and which do not modify utmp. |
| 269 |
Linux uses the BSD conventions for line contents, as documented above. |
| 270 |
.P |
| 271 |
.\" mtk: What is the referrent of "them" in the following sentence? |
| 272 |
.\" System V only uses the type field to mark them and logs |
| 273 |
.\" informative messages such as \fB"new time"\fP in the line field. |
| 274 |
System V has no \fIut_host\fP or \fIut_addr_v6\fP fields. |
| 275 |
.SH NOTES |
| 276 |
Unlike various other |
| 277 |
systems, where utmp logging can be disabled by removing the file, utmp |
| 278 |
must always exist on Linux. |
| 279 |
If you want to disable |
| 280 |
.BR who (1), |
| 281 |
then do not make utmp world readable. |
| 282 |
.P |
| 283 |
The file format is machine-dependent, so it is recommended that it be |
| 284 |
processed only on the machine architecture where it was created. |
| 285 |
.P |
| 286 |
Note that on \fIbiarch\fP platforms, that is, systems which can run both |
| 287 |
32-bit and 64-bit applications (x86-64, ppc64, s390x, etc.), |
| 288 |
\fIut_tv\fP is the same size in 32-bit mode as in 64-bit mode. |
| 289 |
The same goes for \fIut_session\fP and \fIut_time\fP if they are present. |
| 290 |
This allows data files and shared memory to be shared between |
| 291 |
32-bit and 64-bit applications. |
| 292 |
This is achieved by changing the type of |
| 293 |
.I ut_session |
| 294 |
to |
| 295 |
.IR int32_t , |
| 296 |
and that of |
| 297 |
.I ut_tv |
| 298 |
to a struct with two |
| 299 |
.I int32_t |
| 300 |
fields |
| 301 |
.I tv_sec |
| 302 |
and |
| 303 |
.IR tv_usec . |
| 304 |
Since \fIut_tv\fP may not be the same as \fIstruct timeval\fP, |
| 305 |
then instead of the call: |
| 306 |
.P |
| 307 |
.in +4n |
| 308 |
.EX |
| 309 |
gettimeofday((struct timeval *) &ut.ut_tv, NULL); |
| 310 |
.EE |
| 311 |
.in |
| 312 |
.P |
| 313 |
the following method of setting this field is recommended: |
| 314 |
.P |
| 315 |
.in +4n |
| 316 |
.EX |
| 317 |
struct utmp ut; |
| 318 |
struct timeval tv; |
| 319 |
\& |
| 320 |
gettimeofday(&tv, NULL); |
| 321 |
ut.ut_tv.tv_sec = tv.tv_sec; |
| 322 |
ut.ut_tv.tv_usec = tv.tv_usec; |
| 323 |
.EE |
| 324 |
.in |
| 325 |
.\" .P |
| 326 |
.\" Note that the \fIutmp\fP struct from libc5 has changed in libc6. |
| 327 |
.\" Because of this, |
| 328 |
.\" binaries using the old libc5 struct will corrupt |
| 329 |
.\" .IR /var/run/utmp " and/or " /var/log/wtmp . |
| 330 |
.\" .SH BUGS |
| 331 |
.\" This man page is based on the libc5 one, things may work differently now. |
| 332 |
.SH SEE ALSO |
| 333 |
.BR ac (1), |
| 334 |
.BR date (1), |
| 335 |
.BR init (1), |
| 336 |
.BR last (1), |
| 337 |
.BR login (1), |
| 338 |
.BR logname (1), |
| 339 |
.BR lslogins (1), |
| 340 |
.BR users (1), |
| 341 |
.BR utmpdump (1), |
| 342 |
.BR who (1), |
| 343 |
.BR getutent (3), |
| 344 |
.BR getutmp (3), |
| 345 |
.BR login (3), |
| 346 |
.BR logout (3), |
| 347 |
.BR logwtmp (3), |
| 348 |
.BR updwtmp (3) |