1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-05 09:14:03 +00:00
freebsd/include/utmpx.h
Ed Schouten a627ac61ab Implement <utmpx.h>.
The utmpx interface is the standardized interface of the user accounting
database. The standard only defines a subset of the functions that were
present in System V-like systems.

I'd like to highlight some of the traits my implementation has:

- The standard allows the on-disk format to be different than the
  in-memory representation (struct utmpx). Most operating systems don't
  do this, but we do. This allows us to keep our ABI more stable, while
  giving us the opportunity to modify the on-disk format. It also allows
  us to use a common file format across different architectures (i.e.
  byte ordering).

- Our implementation of pututxline() also updates wtmp and lastlog (now
  called utx.log and utx.lastlogin). This means the databases are more
  likely to be in sync.

- Care must be taken that our implementation discard any fields that are
  not applicable. For example, our DEAD_PROCESS records do not hold a
  TTY name. Just a time stamp, a record identifier and a process
  identifier. It also guarantees that strings (ut_host, ut_line and
  ut_user) are null terminated. ut_id is obviously not null terminated,
  because it's not a string.

- The API and its behaviour should be conformant to POSIX, but there may
  be things that slightly deviate from the standard. This implementation
  uses separate file descriptors when writing to the log files. It also
  doesn't use getutxid() to search for a field to overwrite. It uses an
  allocation strategy similar to getutxid(), but prevents DEAD_PROCESS
  records from accumulating.

Make sure libulog doesn't overwrite the manpages shipped with our C
library. Also keep the symbol list in Symbol.map sorted.

I'll bump __FreeBSD_version later this evening. I first want to convert
everything to <utmpx.h> and get rid of <utmp.h>.
2010-01-13 17:29:55 +00:00

89 lines
3.0 KiB
C

/*-
* Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org>
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* $FreeBSD$
*/
#ifndef _UTMPX_H_
#define _UTMPX_H_
#include <sys/cdefs.h>
#include <sys/_timeval.h>
#include <sys/_types.h>
#ifndef _PID_T_DECLARED
typedef __pid_t pid_t;
#define _PID_T_DECLARED
#endif
struct utmpx {
short ut_type; /* Type of entry. */
struct timeval ut_tv; /* Time entry was made. */
char ut_id[8]; /* Record identifier. */
pid_t ut_pid; /* Process ID. */
char ut_user[32]; /* User login name. */
char ut_line[16]; /* Device name. */
#if __BSD_VISIBLE
char ut_host[128]; /* Remote hostname. */
#else
char __ut_host[128];
#endif
char __ut_spare[64];
};
#define EMPTY 0 /* No valid user accounting information. */
#define BOOT_TIME 1 /* Time of system boot. */
#define OLD_TIME 2 /* Time when system clock changed. */
#define NEW_TIME 3 /* Time after system clock changed. */
#define USER_PROCESS 4 /* A process. */
#define INIT_PROCESS 5 /* A process spawned by the init process. */
#define LOGIN_PROCESS 6 /* The session leader of a logged-in user. */
#define DEAD_PROCESS 7 /* A session leader who has exited. */
#if __BSD_VISIBLE
#define SHUTDOWN_TIME 8 /* Time of system shutdown. */
#endif
#if __BSD_VISIBLE
#define UTXDB_ACTIVE 0 /* Active login sessions. */
#define UTXDB_LASTLOGIN 1 /* Last login sessions. */
#define UTXDB_LOG 2 /* Log indexed by time. */
#endif
__BEGIN_DECLS
void endutxent(void);
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *);
struct utmpx *getutxline(const struct utmpx *);
struct utmpx *pututxline(const struct utmpx *);
void setutxent(void);
#if __BSD_VISIBLE
struct utmpx *getutxuser(const char *);
int setutxdb(int, const char *);
#endif
__END_DECLS
#endif /* !_UTMPX_H_ */