/*
* Copyright (c) 2000 Andre Lucas. All rights reserved.
* Portions copyright (c) 1998 Todd C. Miller
* Portions copyright (c) 1996 Jason Downs
* Portions copyright (c) 1996 Theo de Raadt
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Markus Friedl.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
** loginrec.c: platform-independent login recording and lastlog retrieval
**/
/*
The new login code explained
============================
This code attempts to provide a common interface to login recording
(utmp and friends) and last login time retrieval.
Its primary means of achieving this is to use 'struct logininfo', a
union of all the useful fields in the various different types of
system login record structures one finds on UNIX variants.
We depend on autoconf to define which recording methods are to be
used, and which fields are contained in the relevant data structures
on the local system. Many C preprocessor symbols affect which code
gets compiled here.
The code is designed to make it easy to modify a particular
recording method, without affecting other methods nor requiring so
many nested conditional compilation blocks as were commonplace in
the old code.
For login recording, we try to use the local system's libraries as
these are clearly most likely to work correctly. For utmp systems
this usually means login() and logout() or setutent() etc., probably
in libutil, along with logwtmp() etc. On these systems, we fall back
to writing the files directly if we have to, though this method
requires very thorough testing so we do not corrupt local auditing
information. These files and their access methods are very system