xref: /netbsd-src/include/utmpx.h (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: utmpx.h,v 1.14 2006/09/22 21:31:55 christos 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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 #ifndef	_UTMPX_H_
39 #define	_UTMPX_H_
40 
41 #include <sys/cdefs.h>
42 #include <sys/featuretest.h>
43 #include <sys/socket.h>
44 #include <sys/time.h>
45 
46 #define	_PATH_UTMPX		"/var/run/utmpx"
47 #define	_PATH_WTMPX		"/var/log/wtmpx"
48 #define	_PATH_LASTLOGX		"/var/log/lastlogx"
49 #define	_PATH_UTMP_UPDATE	"/usr/libexec/utmp_update"
50 
51 #define _UTX_USERSIZE	32
52 #define _UTX_LINESIZE	32
53 #define	_UTX_IDSIZE	4
54 #define _UTX_HOSTSIZE	256
55 
56 #if defined(_NETBSD_SOURCE)
57 #define UTX_USERSIZE	_UTX_USERSIZE
58 #define UTX_LINESIZE	_UTX_LINESIZE
59 #define	UTX_IDSIZE	_UTX_IDSIZE
60 #define UTX_HOSTSIZE	_UTX_HOSTSIZE
61 #endif
62 
63 #define EMPTY		0
64 #define RUN_LVL		1
65 #define BOOT_TIME	2
66 #define OLD_TIME	3
67 #define NEW_TIME	4
68 #define INIT_PROCESS	5
69 #define LOGIN_PROCESS	6
70 #define USER_PROCESS	7
71 #define DEAD_PROCESS	8
72 
73 #if defined(_NETBSD_SOURCE)
74 #define ACCOUNTING	9
75 #define SIGNATURE	10
76 #define DOWN_TIME	11
77 
78 /*
79  * Strings placed in the ut_line field to indicate special type entries
80  */
81 #define	RUNLVL_MSG	"run-level %c"
82 #define	BOOT_MSG	"system boot"
83 #define	OTIME_MSG	"old time"
84 #define	NTIME_MSG	"new time"
85 #define	DOWN_MSG	"system down"
86 #endif
87 
88 /*
89  * The following structure describes the fields of the utmpx entries
90  * stored in _PATH_UTMPX or _PATH_WTMPX. This is not the format the
91  * entries are stored in the files, and application should only access
92  * entries using routines described in getutxent(3).
93  */
94 
95 #define ut_user ut_name
96 #define ut_xtime ut_tv.tv_sec
97 
98 struct utmpx {
99 	char ut_name[_UTX_USERSIZE];	/* login name */
100 	char ut_id[_UTX_IDSIZE];	/* inittab id */
101 	char ut_line[_UTX_LINESIZE];	/* tty name */
102 	char ut_host[_UTX_HOSTSIZE];	/* host name */
103 	uint16_t ut_session;		/* session id used for windowing */
104 	uint16_t ut_type;		/* type of this entry */
105 	pid_t ut_pid;			/* process id creating the entry */
106 	struct {
107 		uint16_t e_termination;	/* process termination signal */
108 		uint16_t e_exit;	/* process exit status */
109 	} ut_exit;
110 	struct sockaddr_storage ut_ss;	/* address where entry was made from */
111 	struct timeval ut_tv;		/* time entry was created */
112 	uint32_t ut_pad[10];		/* reserved for future use */
113 };
114 
115 #if defined(_NETBSD_SOURCE)
116 struct lastlogx {
117 	struct timeval ll_tv;		/* time entry was created */
118 	char ll_line[_UTX_LINESIZE];	/* tty name */
119 	char ll_host[_UTX_HOSTSIZE];	/* host name */
120 	struct sockaddr_storage ll_ss;	/* address where entry was made from */
121 };
122 #endif	/* !_XOPEN_SOURCE */
123 
124 __BEGIN_DECLS
125 
126 void setutxent(void);
127 void endutxent(void);
128 struct utmpx *getutxent(void);
129 struct utmpx *getutxid(const struct utmpx *);
130 struct utmpx *getutxline(const struct utmpx *);
131 struct utmpx *pututxline(const struct utmpx *);
132 
133 #if defined(_NETBSD_SOURCE)
134 int updwtmpx(const char *, const struct utmpx *);
135 #ifndef __LIBC12_SOURCE__
136 struct lastlogx *getlastlogx(const char *, uid_t, struct lastlogx *)
137     __RENAME(__getlastlogx13);
138 #endif
139 int updlastlogx(const char *, uid_t, struct lastlogx *);
140 struct utmp;
141 void getutmp(const struct utmpx *, struct utmp *);
142 void getutmpx(const struct utmp *, struct utmpx *);
143 
144 int utmpxname(const char *);
145 
146 #endif /* _NETBSD_SOURCE */
147 
148 __END_DECLS
149 
150 #endif /* !_UTMPX_H_ */
151