xref: /dragonfly/include/utmpx.h (revision c01b40e7)
159a92d18SAlex Hornung /*-
259a92d18SAlex Hornung  * Copyright (c) 2002 The NetBSD Foundation, Inc.
359a92d18SAlex Hornung  * All rights reserved.
459a92d18SAlex Hornung  *
559a92d18SAlex Hornung  * This code is derived from software contributed to The NetBSD Foundation
659a92d18SAlex Hornung  * by Christos Zoulas.
759a92d18SAlex Hornung  *
859a92d18SAlex Hornung  * Redistribution and use in source and binary forms, with or without
959a92d18SAlex Hornung  * modification, are permitted provided that the following conditions
1059a92d18SAlex Hornung  * are met:
1159a92d18SAlex Hornung  * 1. Redistributions of source code must retain the above copyright
1259a92d18SAlex Hornung  *    notice, this list of conditions and the following disclaimer.
1359a92d18SAlex Hornung  * 2. Redistributions in binary form must reproduce the above copyright
1459a92d18SAlex Hornung  *    notice, this list of conditions and the following disclaimer in the
1559a92d18SAlex Hornung  *    documentation and/or other materials provided with the distribution.
1659a92d18SAlex Hornung  *
1759a92d18SAlex Hornung  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1859a92d18SAlex Hornung  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1959a92d18SAlex Hornung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2059a92d18SAlex Hornung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2159a92d18SAlex Hornung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2259a92d18SAlex Hornung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2359a92d18SAlex Hornung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2459a92d18SAlex Hornung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2559a92d18SAlex Hornung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2659a92d18SAlex Hornung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2759a92d18SAlex Hornung  * POSSIBILITY OF SUCH DAMAGE.
2859a92d18SAlex Hornung  */
2959a92d18SAlex Hornung 
3059a92d18SAlex Hornung #ifndef	_UTMPX_H_
3159a92d18SAlex Hornung #define	_UTMPX_H_
3259a92d18SAlex Hornung 
3359a92d18SAlex Hornung #include <sys/cdefs.h>
3459a92d18SAlex Hornung #include <sys/socket.h>
3559a92d18SAlex Hornung #include <sys/time.h>
3659a92d18SAlex Hornung 
37*643098a9SSascha Wildner #ifndef _PID_T_DECLARED
38*643098a9SSascha Wildner typedef	__pid_t		pid_t;		/* process id */
39*643098a9SSascha Wildner #define	_PID_T_DECLARED
40*643098a9SSascha Wildner #endif
41*643098a9SSascha Wildner 
4259a92d18SAlex Hornung #define	_PATH_UTMPX		"/var/run/utmpx"
4359a92d18SAlex Hornung #define	_PATH_WTMPX		"/var/log/wtmpx"
4459a92d18SAlex Hornung #define	_PATH_LASTLOGX		"/var/log/lastlogx"
4559a92d18SAlex Hornung #define	_PATH_UTMP_UPDATE	"/usr/libexec/utmp_update"
4659a92d18SAlex Hornung 
4759a92d18SAlex Hornung #define _UTX_USERSIZE	32
4859a92d18SAlex Hornung #define _UTX_LINESIZE	32
4959a92d18SAlex Hornung #define	_UTX_IDSIZE	4
5059a92d18SAlex Hornung #define _UTX_HOSTSIZE	256
5159a92d18SAlex Hornung 
52693258b3SSascha Wildner #if __BSD_VISIBLE
5359a92d18SAlex Hornung #define UTX_USERSIZE	_UTX_USERSIZE
5459a92d18SAlex Hornung #define UTX_LINESIZE	_UTX_LINESIZE
5559a92d18SAlex Hornung #define	UTX_IDSIZE	_UTX_IDSIZE
5659a92d18SAlex Hornung #define UTX_HOSTSIZE	_UTX_HOSTSIZE
57693258b3SSascha Wildner #endif
5859a92d18SAlex Hornung 
5959a92d18SAlex Hornung 
60693258b3SSascha Wildner #define EMPTY		0	/* No valid user accounting information. */
6169df205fSSascha Wildner #if __BSD_VISIBLE
6259a92d18SAlex Hornung #define RUN_LVL		1
6369df205fSSascha Wildner #endif
64693258b3SSascha Wildner #define BOOT_TIME	2	/* Time of system boot. */
65693258b3SSascha Wildner #define OLD_TIME	3	/* Time when system clock changed. */
66693258b3SSascha Wildner #define NEW_TIME	4	/* Time after system clock changed. */
67693258b3SSascha Wildner #define INIT_PROCESS	5	/* A process spawned by the init process. */
68693258b3SSascha Wildner #define LOGIN_PROCESS	6	/* The session leader of a logged-in user. */
69693258b3SSascha Wildner #define USER_PROCESS	7	/* A process. */
70693258b3SSascha Wildner #define DEAD_PROCESS	8	/* A session leader who has exited. */
7159a92d18SAlex Hornung 
72693258b3SSascha Wildner #if __BSD_VISIBLE
7359a92d18SAlex Hornung #define ACCOUNTING	9
7459a92d18SAlex Hornung #define SIGNATURE	10
7559a92d18SAlex Hornung #define DOWN_TIME	11
7659a92d18SAlex Hornung 
7759a92d18SAlex Hornung /*
7859a92d18SAlex Hornung  * Strings placed in the ut_line field to indicate special type entries
7959a92d18SAlex Hornung  */
8059a92d18SAlex Hornung #define	RUNLVL_MSG	"run-level %c"
8159a92d18SAlex Hornung #define	BOOT_MSG	"system boot"
8259a92d18SAlex Hornung #define	OTIME_MSG	"old time"
8359a92d18SAlex Hornung #define	NTIME_MSG	"new time"
8459a92d18SAlex Hornung #define	DOWN_MSG	"system down"
8559a92d18SAlex Hornung 
8659a92d18SAlex Hornung typedef enum {
8759a92d18SAlex Hornung 	UTX_DB_UTMPX,
8859a92d18SAlex Hornung 	UTX_DB_WTMPX,
8959a92d18SAlex Hornung 	UTX_DB_LASTLOGX
9059a92d18SAlex Hornung } utx_db_t;
91693258b3SSascha Wildner #endif
9259a92d18SAlex Hornung 
9359a92d18SAlex Hornung struct exit_status
9459a92d18SAlex Hornung {
95*643098a9SSascha Wildner 	__uint16_t e_termination;	/* termination status */
96*643098a9SSascha Wildner 	__uint16_t e_exit;		/* exit status */
9759a92d18SAlex Hornung };
9859a92d18SAlex Hornung 
99693258b3SSascha Wildner /*
100693258b3SSascha Wildner  * The following structure describes the fields of the utmpx entries
101693258b3SSascha Wildner  * stored in _PATH_UTMPX or _PATH_WTMPX. This is not necessarily the
102693258b3SSascha Wildner  * format the entries are stored in the files, and application should
103693258b3SSascha Wildner  * only access entries using routines described in getutxent(3).
104693258b3SSascha Wildner  */
105693258b3SSascha Wildner 
106693258b3SSascha Wildner #define ut_user ut_name
107693258b3SSascha Wildner #define ut_xtime ut_tv.tv_sec
108693258b3SSascha Wildner 
10959a92d18SAlex Hornung struct utmpx {
11059a92d18SAlex Hornung 	char ut_name[_UTX_USERSIZE];	/* login name */
11159a92d18SAlex Hornung 	char ut_id[_UTX_IDSIZE];	/* inittab id */
11259a92d18SAlex Hornung 	char ut_line[_UTX_LINESIZE];	/* tty name */
11359a92d18SAlex Hornung 	char ut_host[_UTX_HOSTSIZE];	/* host name */
114*643098a9SSascha Wildner 	__uint8_t ut_unused[16];	/* reserved for future use */
115*643098a9SSascha Wildner 	__uint16_t ut_session;		/* session id used for windowing */
11614f65205SSascha Wildner 	short ut_type;			/* type of this entry */
11759a92d18SAlex Hornung 	pid_t ut_pid;			/* process id creating the entry */
11859a92d18SAlex Hornung 	struct exit_status ut_exit;	/* process termination/exit status */
11959a92d18SAlex Hornung 	struct sockaddr_storage ut_ss;	/* address where entry was made from */
12059a92d18SAlex Hornung 	struct timeval ut_tv;		/* time entry was created */
121*643098a9SSascha Wildner 	__uint8_t ut_unused2[16];	/* reserved for future use */
12259a92d18SAlex Hornung };
12359a92d18SAlex Hornung 
124693258b3SSascha Wildner #if __BSD_VISIBLE
12559a92d18SAlex Hornung struct lastlogx {
12659a92d18SAlex Hornung 	struct timeval ll_tv;		/* time entry was created */
12759a92d18SAlex Hornung 	char ll_line[_UTX_LINESIZE];	/* tty name */
12859a92d18SAlex Hornung 	char ll_host[_UTX_HOSTSIZE];	/* host name */
12959a92d18SAlex Hornung 	struct sockaddr_storage ll_ss;	/* address where entry was made from */
13059a92d18SAlex Hornung };
131693258b3SSascha Wildner #endif
13259a92d18SAlex Hornung 
133c4fc0030SSascha Wildner __BEGIN_DECLS
134c4fc0030SSascha Wildner void          endutxent(void);
135c4fc0030SSascha Wildner struct utmpx *getutxent(void);
136c4fc0030SSascha Wildner struct utmpx *getutxid(const struct utmpx *);
137c4fc0030SSascha Wildner struct utmpx *getutxline(const struct utmpx *);
138c4fc0030SSascha Wildner struct utmpx *pututxline(const struct utmpx *);
139c4fc0030SSascha Wildner void          setutxent(void);
140c4fc0030SSascha Wildner 
141f33ef0a8SSascha Wildner #if __BSD_VISIBLE
142bdb02cd9SAlex Hornung int _updwtmpx(const char *, const struct utmpx *);
143bdb02cd9SAlex Hornung void updwtmpx(const char *, const struct utmpx *);
14459a92d18SAlex Hornung struct lastlogx *getlastlogx(const char *, uid_t, struct lastlogx *);
14559a92d18SAlex Hornung int updlastlogx(const char *, uid_t, struct lastlogx *);
14659a92d18SAlex Hornung int utmpxname(const char *);
147974aa081SSascha Wildner struct utmpx *getutxuser(const char *);
1487bb7a6edSSascha Wildner int setutxdb(utx_db_t, const char *);
149c4fc0030SSascha Wildner #endif
150c4fc0030SSascha Wildner __END_DECLS
15159a92d18SAlex Hornung 
15259a92d18SAlex Hornung #endif /* _UTMPX_H_ */
153