]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man5/utmp.5
ffix
[thirdparty/man-pages.git] / man5 / utmp.5
1 .\" Copyright (c) 1993 Michael Haardt (michael@cantor.informatik.rwth-aachen.de), Fri Apr 2 11:32:09 MET DST 1993
2 .\"
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
7 .\"
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
12 .\"
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 .\" GNU General Public License for more details.
17 .\"
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
21 .\" USA.
22 .\"
23 .\" Modified 1993-07-25 by Rik Faith (faith@cs.unc.edu)
24 .\" Modified 1995-02-26 by Michael Haardt
25 .\" Modified 1996-07-20 by Michael Haardt
26 .\" Modified 1997-07-02 by Nicolás Lichtmaier <nick@debian.org>
27 .\" Modified 2004-10-31 by aeb, following Gwenole Beauchesne
28 .TH UTMP 5 2007-11-25 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 utmp, wtmp \- login records
31 .SH SYNOPSIS
32 .B #include <utmp.h>
33 .SH DESCRIPTION
34 The
35 .I utmp
36 file allows one to discover information about who is currently using the
37 system.
38 There may be more users currently using the system, because not
39 all programs use utmp logging.
40 .PP
41 .B Warning:
42 .I utmp
43 must not be writable, because many system programs (foolishly)
44 depend on its integrity.
45 You risk faked system logfiles and
46 modifications of system files if you leave
47 .I utmp
48 writable to any user.
49 .PP
50 The file is a sequence of entries with the following structure declared
51 in the include file (note that this is only one of several definitions
52 around; details depend on the version of libc):
53 .in +4n
54 .nf
55 .sp
56 #define UT_UNKNOWN 0
57 #define RUN_LVL 1
58 #define BOOT_TIME 2
59 #define NEW_TIME 3
60 #define OLD_TIME 4
61 #define INIT_PROCESS 5
62 #define LOGIN_PROCESS 6
63 #define USER_PROCESS 7
64 #define DEAD_PROCESS 8
65 #define ACCOUNTING 9
66
67 #define UT_LINESIZE 12
68 #define UT_NAMESIZE 32
69 #define UT_HOSTSIZE 256
70
71 struct exit_status {
72 short int e_termination; /* Process termination status */
73 short int e_exit; /* Process exit status */
74 };
75
76 struct utmp {
77 short ut_type; /* Type of record */
78 pid_t ut_pid; /* PID of login process */
79 char ut_line[UT_LINESIZE]; /* Device name of tty \- "/dev/" */
80 char ut_id[4]; /* Terminal name suffix,
81 or inittab(5) ID */
82 char ut_user[UT_NAMESIZE]; /* Username */
83 char ut_host[UT_HOSTSIZE]; /* Hostname for remote login, or
84 kernel version for run-level
85 messages */
86 struct exit_status ut_exit; /* Exit status of a process
87 marked as DEAD_PROCESS; not
88 used by Linux init(8) */
89 /* The ut_session and ut_tv fields must be the same size when
90 compiled 32- and 64-bit. This allows data files and shared
91 memory to be shared between 32- and 64-bit applications. */
92 #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
93 int32_t ut_session; /* Session ID, used for windowing */
94 struct {
95 int32_t tv_sec; /* Seconds */
96 int32_t tv_usec; /* Microseconds */
97 } ut_tv; /* Time entry was made */
98 #else
99 long ut_session; /* Session ID, used for windowing */
100 struct timeval ut_tv; /* Time entry was made */
101 #endif
102
103 int32_t ut_addr_v6[4]; /* Internet address of remote
104 host; IPv4 address uses
105 just ut_addr_v6[0] */
106 char __unused[20]; /* Reserved for future use */
107 };
108
109 /* Backwards compatibility hacks. */
110 #define ut_name ut_user
111 #ifndef _NO_UT_TIME
112 #define ut_time ut_tv.tv_sec
113 #endif
114 #define ut_xtime ut_tv.tv_sec
115 #define ut_addr ut_addr_v6[0]
116 .sp
117 .fi
118 .in
119 This structure gives the name of the special file associated with the
120 user's terminal, the user's login name, and the time of login in the form
121 of
122 .BR time (2).
123 String fields are terminated by \fB\(aq\e0\(aq\fP
124 if they are shorter than the size
125 of the field.
126 .PP
127 The first entries ever created result from
128 .BR init (8)
129 processing
130 .BR inittab (5).
131 Before an entry is processed, though,
132 .BR init (8)
133 cleans up utmp by setting \fIut_type\fP to \fBDEAD_PROCESS\fP, clearing
134 \fIut_user\fP, \fIut_host\fP, and \fIut_time\fP with null bytes for each
135 record which \fIut_type\fP is not \fBDEAD_PROCESS\fP or \fBRUN_LVL\fP
136 and where no process with PID \fIut_pid\fP exists.
137 If no empty record
138 with the needed \fIut_id\fP can be found, init creates a new one.
139 It sets \fIut_id\fP from the inittab, \fIut_pid\fP and \fIut_time\fP to the
140 current values, and \fIut_type\fP to \fBINIT_PROCESS\fP.
141 .PP
142 .BR mingetty (8)
143 (or
144 .BR agetty (8))
145 locates the entry by the PID, changes \fIut_type\fP to
146 \fBLOGIN_PROCESS\fP, changes \fIut_time\fP, sets \fIut_line\fP, and waits
147 for connection to be established.
148 .BR login (1),
149 after a user has been
150 authenticated, changes \fIut_type\fP to \fBUSER_PROCESS\fP, changes
151 \fIut_time\fP, and sets \fIut_host\fP and \fIut_addr\fP.
152 Depending on
153 .BR mingetty (8)
154 (or
155 .BR agetty (8))
156 and
157 .BR login (1),
158 records may be located by
159 \fIut_line\fP instead of the preferable \fIut_pid\fP.
160 .PP
161 When
162 .BR init (8)
163 finds that a process has exited, it locates its utmp
164 entry by \fIut_pid\fP, sets \fIut_type\fP to \fBDEAD_PROCESS\fP, and
165 clears \fIut_user\fP, \fIut_host\fP and \fIut_time\fP with null bytes.
166 .PP
167 .BR xterm (1)
168 and other terminal emulators directly create a
169 \fBUSER_PROCESS\fP record and generate the \fIut_id\fP by using the last
170 two letters of \fI/dev/ttyp\fP\fI%c\fP or by using \fIp\fP\fI%d\fP for
171 \fI/dev/pts/\fP\fI%d\fP.
172 If they find a \fBDEAD_PROCESS\fP for this ID,
173 they recycle it, otherwise they create a new entry.
174 If they can, they
175 will mark it as \fBDEAD_PROCESS\fP on exiting and it is advised that
176 they null \fIut_line\fP, \fIut_time\fP, \fIut_user\fP, and \fIut_host\fP
177 as well.
178 .PP
179 .BR telnetd (8)
180 sets up a \fBLOGIN_PROCESS\fP entry and leaves the rest to
181 .BR login (1)
182 as usual.
183 After the telnet session ends,
184 .BR telnetd (8)
185 cleans up utmp in the described way.
186 .PP
187 The \fIwtmp\fP file records all logins and logouts.
188 Its format is exactly like \fIutmp\fP except that a null user name
189 indicates a logout
190 on the associated terminal.
191 Furthermore, the terminal name \fB~\fP
192 with user name \fBshutdown\fP or \fBreboot\fP indicates a system
193 shutdown or reboot and the pair of terminal names \fB|\fP/\fB}\fP
194 logs the old/new system time when
195 .BR date (1)
196 changes it.
197 \fIwtmp\fP is maintained by
198 .BR login (1),
199 .BR init (8),
200 and some versions of
201 .BR getty (8)
202 (e.g.,
203 .BR mingetty (8)
204 or
205 .BR agetty (8)).
206 Neither of these programs creates the file, so if it is
207 removed, record-keeping is turned off.
208 .PP
209 Note that on \fIbiarch\fP platforms, that is, systems which can run both
210 32-bit and 64-bit applications (x86-64, ppc64, s390x, etc.),
211 \fIut_tv\fP is the same size in 32-bit mode as in 64-bit mode.
212 The same goes for \fIut_session\fP and \fIut_time\fP if they are present.
213 This allows data files and shared memory to be shared between
214 32-bit and 64-bit applications.
215 Since \fIut_tv\fP may not be the same as \fIstruct timeval\fP,
216 then instead of the call:
217 .in +4n
218 .nf
219 .sp
220 gettimeofday((struct timeval *) &ut.ut_tv, NULL);
221 .fi
222 .in
223
224 the following method of setting this field is recommended:
225 .in +4n
226 .nf
227 .sp
228 struct utmp ut;
229 struct timeval tv;
230
231 gettimeofday(&tv, NULL);
232 ut.ut_tv.tv_sec = tv.tv_sec;
233 ut.ut_tv.tv_usec = tv.tv_usec;
234 .fi
235 .in
236 .SH FILES
237 /var/run/utmp
238 .br
239 /var/log/wtmp
240 .SH "CONFORMING TO"
241 Linux utmp entries conform neither to v7/BSD nor to System V; they are a
242 mix of the two.
243 v7/BSD has fewer fields; most importantly it lacks
244 \fIut_type\fP, which causes native v7/BSD-like programs to display (for
245 example) dead or login entries.
246 Further, there is no configuration file
247 which allocates slots to sessions.
248 BSD does so because it lacks \fIut_id\fP fields.
249 In Linux (as in System V), the \fIut_id\fP field of a
250 record will never change once it has been set, which reserves that slot
251 without needing a configuration file.
252 Clearing \fIut_id\fP may result
253 in race conditions leading to corrupted utmp entries and potential
254 security holes.
255 Clearing the above mentioned fields by filling them
256 with null bytes is not required by System V semantics, but it allows to run
257 many programs which assume BSD semantics and which do not modify utmp.
258 Linux uses the BSD conventions for line contents, as documented above.
259 .PP
260 System V only uses the type field to mark them and logs informative messages
261 such as \fB"new time"\fP in the line field.
262 \fBUT_UNKNOWN\fP seems
263 to be a Linux invention.
264 System V has no \fIut_host\fP or \fIut_addr_v6\fP fields.
265 .PP
266 Unlike various other
267 systems, where utmp logging can be disabled by removing the file, utmp
268 must always exist on Linux.
269 If you want to disable
270 .BR who (1)
271 then do not make utmp world readable.
272 .PP
273 Note that the \fIutmp\fP struct from libc5 has changed in libc6.
274 Because of this,
275 binaries using the old libc5 struct will corrupt
276 .IR /var/run/utmp " and/or " /var/log/wtmp .
277 .SH NOTES
278 The file format is machine-dependent, so it is recommended that it be
279 processed only on the machine architecture where it was created.
280 .PP
281 Note that on platforms which can run both 32-bit and 64-bit applications
282 (x86-64, ppc64, s390x, etc.), the sizes of the fields of a \fIutmp\fP struct
283 must be the same in 32-bit mode as in 64-bit mode.
284 This is achieved by changing the type of
285 .I ut_session
286 to
287 .IR int32_t ,
288 and that of
289 .I ut_tv
290 to a struct with two
291 .I int32_t
292 fields
293 .I tv_sec
294 and
295 .IR tv_usec .
296 (Thus, in order to fill it, first get the
297 time into a real \fIstruct timeval\fP,
298 then copy the two fields to
299 .IR ut_tv .)
300 .SH BUGS
301 This man page is based on the libc5 one, things may work differently now.
302 .SH "SEE ALSO"
303 .BR ac (1),
304 .BR date (1),
305 .BR last (1),
306 .BR login (1),
307 .BR who (1),
308 .BR getutent (3),
309 .BR login (3),
310 .BR logout (3),
311 .BR logwtmp (3),
312 .BR updwtmp (3),
313 .BR init (8)