1/*	$NetBSD: utmpx.h,v 1.18 2021/08/15 00:36:11 gutteridge Exp $	 */
2
3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31#ifndef	_UTMPX_H_
32#define	_UTMPX_H_
33
34#include <sys/cdefs.h>
35#include <sys/featuretest.h>
36#include <sys/socket.h>
37#include <sys/time.h>
38
39#define	_PATH_UTMPX		"/var/run/utmpx"
40#define	_PATH_WTMPX		"/var/log/wtmpx"
41#define	_PATH_LASTLOGX		"/var/log/lastlogx"
42#define	_PATH_UTMP_UPDATE	"/usr/libexec/utmp_update"
43
44#define _UTX_USERSIZE	32
45#define _UTX_LINESIZE	32
46#define	_UTX_IDSIZE	4
47#define _UTX_HOSTSIZE	256
48
49#if defined(_NETBSD_SOURCE)
50#define UTX_USERSIZE	_UTX_USERSIZE
51#define UTX_LINESIZE	_UTX_LINESIZE
52#define	UTX_IDSIZE	_UTX_IDSIZE
53#define UTX_HOSTSIZE	_UTX_HOSTSIZE
54#endif
55
56#define EMPTY		0
57#define RUN_LVL		1
58#define BOOT_TIME	2
59#define OLD_TIME	3
60#define NEW_TIME	4
61#define INIT_PROCESS	5
62#define LOGIN_PROCESS	6
63#define USER_PROCESS	7
64#define DEAD_PROCESS	8
65
66#if defined(_NETBSD_SOURCE)
67#define ACCOUNTING	9
68#define SIGNATURE	10
69#define DOWN_TIME	11
70
71/*
72 * Strings placed in the ut_line field to indicate special type entries
73 */
74#define	RUNLVL_MSG	"run-level %c"
75#define	BOOT_MSG	"system boot"
76#define	OTIME_MSG	"old time"
77#define	NTIME_MSG	"new time"
78#define	DOWN_MSG	"system down"
79#endif
80
81/*
82 * The following structure describes the fields of the utmpx entries
83 * stored in _PATH_UTMPX or _PATH_WTMPX. This is not the format the
84 * entries are stored in the files, and application should only access
85 * entries using routines described in getutxent(3).
86 */
87
88#define ut_user ut_name
89#define ut_xtime ut_tv.tv_sec
90
91/*
92 * This should be:
93 * 40 - (sizeof(struct timeval) - sizeof(struct { long s; long u; })))
94 * but g++ does not like it, to retain size compatibility with v1.00,
95 * so we do it manually.
96 */
97#ifdef _LP64
98#define _UTX_PADSIZE 36
99#else
100#define _UTX_PADSIZE 40
101#endif
102
103struct utmpx {
104	char ut_name[_UTX_USERSIZE];	/* login name */
105	char ut_id[_UTX_IDSIZE];	/* inittab id */
106	char ut_line[_UTX_LINESIZE];	/* tty name */
107	char ut_host[_UTX_HOSTSIZE];	/* host name */
108	uint16_t ut_session;		/* session id used for windowing */
109	uint16_t ut_type;		/* type of this entry */
110	pid_t ut_pid;			/* process id creating the entry */
111	struct {
112		uint16_t e_termination;	/* process termination signal */
113		uint16_t e_exit;	/* process exit status */
114	} ut_exit;
115	struct sockaddr_storage ut_ss;	/* address where entry was made from */
116	struct timeval ut_tv;		/* time entry was created */
117	uint8_t ut_pad[_UTX_PADSIZE];	/* reserved for future use */
118};
119
120#if defined(_NETBSD_SOURCE)
121struct lastlogx {
122	struct timeval ll_tv;		/* time entry was created */
123	char ll_line[_UTX_LINESIZE];	/* tty name */
124	char ll_host[_UTX_HOSTSIZE];	/* host name */
125	struct sockaddr_storage ll_ss;	/* address where entry was made from */
126};
127#endif	/* _NETBSD_SOURCE */
128
129__BEGIN_DECLS
130
131void setutxent(void);
132void endutxent(void);
133
134#ifndef __LIBC12_SOURCE__
135struct utmpx *getutxent(void) __RENAME(__getutxent50);
136struct utmpx *getutxid(const struct utmpx *) __RENAME(__getutxid50);
137struct utmpx *getutxline(const struct utmpx *) __RENAME(__getutxline50);
138struct utmpx *pututxline(const struct utmpx *) __RENAME(__pututxline50);
139#endif
140
141#if defined(_NETBSD_SOURCE)
142#ifndef __LIBC12_SOURCE__
143int updwtmpx(const char *, const struct utmpx *) __RENAME(__updwtmpx50);
144struct lastlogx *getlastlogx(const char *, uid_t, struct lastlogx *)
145    __RENAME(__getlastlogx50);
146int updlastlogx(const char *, uid_t, struct lastlogx *)
147    __RENAME(__updlastlogx50);
148struct utmp;
149void getutmp(const struct utmpx *, struct utmp *) __RENAME(__getutmp50);
150void getutmpx(const struct utmp *, struct utmpx *) __RENAME(__getutmpx50);
151#endif
152
153int utmpxname(const char *);
154
155#endif /* _NETBSD_SOURCE */
156
157__END_DECLS
158
159#endif /* !_UTMPX_H_ */
160