xref: /netbsd-src/share/man/man5/utmp.5 (revision fdecd6a253f999ae92b139670d9e15cc9df4497c)
1.\"	$NetBSD: utmp.5,v 1.6 1997/06/22 08:11:08 lukem Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)utmp.5	8.2 (Berkeley) 3/17/94
35.\"
36.Dd March 17, 1994
37.Dt UTMP 5
38.Os BSD 4
39.Sh NAME
40.Nm utmp ,
41.Nm wtmp ,
42.Nm lastlog
43.Nd login records
44.Sh SYNOPSIS
45.Fd #include <utmp.h>
46.Sh DESCRIPTION
47The file
48.Aq Pa utmp.h
49declares the structures used to record information about current
50users in the file
51.Nm utmp ,
52logins and logouts in the file
53.Nm wtmp ,
54and last logins in the file
55.Nm lastlog .
56The time stamps of date changes, shutdowns and reboots are also logged in
57the
58.Nm wtmp
59file.
60.Pp
61These files can grow rapidly on busy systems, daily or weekly rotation
62is recommended.
63If any of these files do not exist, it is not created.
64These
65files must be created manually and are normally maintained in either the script
66.Pa /etc/daily
67or the script
68.Pa /etc/weekly .
69(See
70.Xr cron 8 . )
71.Bd -literal -offset indent
72#define _PATH_UTMP      "/var/run/utmp"
73#define _PATH_WTMP      "/var/log/wtmp"
74#define _PATH_LASTLOG   "/var/log/lastlog"
75
76#define UT_NAMESIZE     8
77#define UT_LINESIZE     8
78#define UT_HOSTSIZE     16
79
80struct lastlog {
81        time_t  ll_time;
82        char    ll_line[UT_LINESIZE];
83        char    ll_host[UT_HOSTSIZE];
84};
85
86struct utmp {
87        char    ut_line[UT_LINESIZE];
88        char    ut_name[UT_NAMESIZE];
89        char    ut_host[UT_HOSTSIZE];
90        time_t	ut_time;
91};
92.Ed
93.Pp
94Each time a user logs in, the
95.Xr login
96program looks up the user's
97.Tn UID
98in the file
99.Nm lastlog .
100If it is found, the timestamp of the last time the user logged
101in, the terminal line and the hostname
102are written to the standard output. (Providing the login is not
103.Em quiet ,
104see
105.Xr login 1 . )
106The
107.Xr login
108program then records the new login time in the file
109.Nm lastlog .
110.Pp
111After the new
112.Fa lastlog
113record is written ,
114.\" the
115.\" .Xr libutil 3
116.\" routine
117the file
118.Nm utmp
119is opened and the
120.Fa utmp
121record for the user inserted.
122This record remains there until
123the user logs out at which time it is deleted (by clearing
124the user and host fields, and updating the timestamp field).
125The
126.Nm utmp
127file is used by the programs
128.Xr rwho 1 ,
129.Xr users 1 ,
130.Xr w 1 ,
131and
132.Xr who 1 .
133.Pp
134Next, the
135.Xr login
136program opens the file
137.Nm wtmp ,
138and appends the user's
139.Fa utmp
140record.
141When the user logs out, a
142.Fa utmp
143record with the tty line, an updated time stamp, and cleared user and host
144fields is appended to the file. (See
145.Xr init 8 . )
146The
147.Nm wtmp
148file is used by the programs
149.Xr last 1
150and
151.Xr ac 8 .
152.Pp
153In the event of a date change, a shutdown or reboot, the
154following items are logged in the
155.Nm wtmp
156file.
157.Pp
158.Bl -tag -width shutdownxx -compact
159.It Li reboot
160.It Li shutdown
161A system reboot or shutdown has been initiated.
162The character
163.Ql \&~
164is placed in the field
165.Fa ut_line ,
166and
167.Li reboot
168or
169.Li shutdown
170in the field
171.Fa ut_name .
172(See
173.Xr shutdown 8
174and
175.Xr reboot 8 . )
176.Pp
177.It Li date
178The system time has been manually or automatically updated.
179(See
180.Xr date 1 . )
181The command name
182.Xr date
183is recorded in the field
184.Fa ut_name .
185In the field
186.Fa ut_line ,
187the character
188.Ql \\*(Ba
189indicates the time prior to the change, and the character
190.Ql \&{
191indicates the new time.
192.El
193.Sh FILES
194.Bl -tag -width /var/log/lastlog -compact
195.It Pa /var/run/utmp
196The
197.Nm utmp
198file.
199.It Pa /var/log/wtmp
200The
201.Nm wtmp
202file.
203.It Pa /var/log/lastlog
204The
205.Nm lastlog
206file.
207.El
208.Sh SEE ALSO
209.Xr last 1 ,
210.Xr login 1 ,
211.Xr who 1 ,
212.Xr ac 8 ,
213.Xr init 8
214.Sh HISTORY
215A
216.Nm utmp
217and
218.Nm wtmp
219file format appeared in
220.At v6 .
221The
222.Nm lastlog
223file format appeared in
224.Bx 3.0 .
225