1 .\" Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 .Nd user accounting database functions
47 .Fn getutxid "const struct utmpx *id"
49 .Fn getutxline "const struct utmpx *line"
51 .Fn getutxuser "const char *user"
53 .Fn pututxline "const struct utmpx *utmpx"
55 .Fn setutxdb "int type" "const char *file"
59 These functions operate on the user accounting database which stores
60 records of various system activities, such as user login and logouts,
61 but also system startups and shutdowns and modifications to the system's
63 The system stores these records in three databases, each having a
65 .Bl -tag -width indent
66 .It Pa /var/run/utx.active
67 Log of currently active user login sessions.
68 This file is similar to the traditional
71 This file only contains process related entries, such as user login and
73 .It Pa /var/log/utx.lastlogin
74 Log of last user login entries per user.
75 This file is similar to the traditional
78 This file only contains user login records for users who have at least
80 .It Pa /var/log/utx.log
81 Log of all entries, sorted by date of addition.
82 This file is similar to the traditional
85 This file may contain any type of record described below.
88 Each entry in these databases is defined by the structure
90 found in the include file
92 .Bd -literal -offset indent
94 short ut_type; /* Type of entry. */
95 struct timeval ut_tv; /* Time entry was made. */
96 char ut_id[]; /* Record identifier. */
97 pid_t ut_pid; /* Process ID. */
98 char ut_user[]; /* User login name. */
99 char ut_line[]; /* Device name. */
100 char ut_host[]; /* Remote hostname. */
106 field indicates the type of the log entry, which can have one of the
108 .Bl -tag -width LOGIN_PROCESS
110 No valid user accounting information.
112 Identifies time of system boot.
114 Identifies time of system shutdown.
116 Identifies time when system clock changed.
118 Identifies time after system clock changed.
120 Identifies a process.
122 Identifies a process spawned by the init process.
124 Identifies the session leader of a logged-in user.
126 Identifies a session leader who has exited.
133 are not processed by this implementation.
135 Other fields inside the structure are:
136 .Bl -tag -width ut_user
138 The time the event occurred.
139 This field is used for all types of entries, except
142 An identifier that is used to refer to the entry.
143 This identifier can be used to remove or replace a login entry by
144 writing a new entry to the database containing the same value for
146 This field is only applicable to entries of type
153 The process identifier of the session leader of the login session.
154 This field is only applicable to entries of type
161 The user login name corresponding with the login session.
162 This field is only applicable to entries of type
168 entries this entry typically contains the name of the login process.
170 The name of the TTY character device, without the leading
172 prefix, corresponding with the device used to facilitate the user login
174 If no TTY character device is used, this field is left blank.
175 This field is only applicable to entries of type
180 The network hostname of the remote system, connecting to perform a user
182 If the user login session is not performed across a network, this field
184 This field is only applicable to entries of type
188 This implementation guarantees all inapplicable fields are discarded.
194 fields of the structure returned by the library functions are also
195 guaranteed to be null-terminated in this implementation.
199 function can be used to read the next entry from the user accounting
204 function searches for the next entry in the database of which the
205 behaviour is based on the
217 it will return the next entry whose
228 it will return the next entry whose
230 has one of the previously mentioned values and whose
236 function searches for the next entry in the database whose
244 is equal to the same field in
249 function searches for the next entry in the database whose
258 The previously mentioned functions will automatically try to open the
259 user accounting database if not already done so.
264 functions allow the database to be opened manually, causing the offset
265 within the user accounting database to be rewound.
268 function closes the database.
272 database always opens the active sessions database.
275 function opens the database identified by
277 whose value is either
282 It will open a custom file with filename
284 instead of the system-default if
287 Care must be taken that when using a custom filename,
289 still has to match with the actual format, since each database may use
294 function writes record
296 to the system-default user accounting databases.
299 determines which databases are modified.
306 will only be written to
307 .Pa /var/log/utx.log .
311 will also be written to
312 .Pa /var/run/utx.active
314 .Pa /var/log/utx.lastlogin .
318 will only be written to
321 .Pa /var/run/utx.active
329 is equal has been found in the latter.
331 In addition, entries of type
335 will cause all existing entries in
336 .Pa /var/run/utx.active
339 All entries whose type has not been mentioned previously, are discarded
340 by this implementation of
342 This implementation also ignores the value of
351 functions return a pointer to an
353 structure that matches the mentioned constraints on success or
355 when reaching the end-of-file or when an error occurs.
359 function returns a pointer to an
361 structure containing a copy of the structure written to disk upon
371 and an entry with an identifier with a value equal to the field
373 was not found; the global variable
375 is set to indicate the error.
379 function returns 0 if the user accounting database was opened
381 Otherwise, -1 is returned and the global variable
383 is set to indicate the error.
385 In addition to the error conditions described in
392 function can generate the following errors:
397 is DEAD_PROCESS, and the process entry could not be found.
401 is not supported by this implementation.
403 In addition to the error conditions described in
407 function can generate the following errors:
412 argument contains a value not supported by this implementation.
414 The file format is invalid.
433 functions are expected to conform to
438 function deviates from the standard by writing its records to multiple
439 database files, depending on its
441 This prevents the need for special utility functions to update the other
442 databases, such as the
446 functions which are available in other implementations.
447 It also tries to replace
449 entries in the active sessions database when storing
451 entries and no entry with the same value for
454 The standard always requires a new entry to be allocated, which could
455 cause an unbounded growth of the database.
470 These functions appeared in
476 .An \&Ed Schouten Aq Mt ed@FreeBSD.org