xref: /onnv-gate/usr/src/head/utmp.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
23*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*0Sstevel@tonic-gate  * Use is subject to license terms.
29*0Sstevel@tonic-gate  */
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifndef _UTMP_H
33*0Sstevel@tonic-gate #define	_UTMP_H
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.5.1.7 */
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate /*
38*0Sstevel@tonic-gate  * Note:  The getutent(3c) family of interfaces are obsolete.
39*0Sstevel@tonic-gate  * The getutxent(3c) family provide a superset of this functionality
40*0Sstevel@tonic-gate  * and should be used in place of getutent(3c).
41*0Sstevel@tonic-gate  */
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #include <sys/types.h>
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #ifdef	__cplusplus
46*0Sstevel@tonic-gate extern "C" {
47*0Sstevel@tonic-gate #endif
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
50*0Sstevel@tonic-gate #define	UTMP_FILE	"/var/adm/utmp"
51*0Sstevel@tonic-gate #define	WTMP_FILE	"/var/adm/wtmp"
52*0Sstevel@tonic-gate #endif
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate #define	ut_name	ut_user
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
57*0Sstevel@tonic-gate struct exit_status {
58*0Sstevel@tonic-gate 	short e_termination;	/* Process termination status */
59*0Sstevel@tonic-gate 	short e_exit;		/* Process exit status */
60*0Sstevel@tonic-gate };
61*0Sstevel@tonic-gate #else
62*0Sstevel@tonic-gate struct ut_exit_status {
63*0Sstevel@tonic-gate 	short ut_e_termination;	/* Process termination status */
64*0Sstevel@tonic-gate 	short ut_e_exit;	/* Process exit status */
65*0Sstevel@tonic-gate };
66*0Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate /*
71*0Sstevel@tonic-gate  * This data structure describes the utmp entries returned by
72*0Sstevel@tonic-gate  * the getutent(3c) family of APIs.  It does not (necessarily)
73*0Sstevel@tonic-gate  * correspond to the contents of the utmp or wtmp files.
74*0Sstevel@tonic-gate  *
75*0Sstevel@tonic-gate  * Applications should only interact with this subsystem via
76*0Sstevel@tonic-gate  * the getutxent(3c) family of APIs, as the getutent(3c) family
77*0Sstevel@tonic-gate  * are obsolete.
78*0Sstevel@tonic-gate  */
79*0Sstevel@tonic-gate struct utmp {
80*0Sstevel@tonic-gate 	char ut_user[8];		/* User login name */
81*0Sstevel@tonic-gate 	char ut_id[4]; 			/* /etc/inittab id(usually line #) */
82*0Sstevel@tonic-gate 	char ut_line[12];		/* device name (console, lnxx) */
83*0Sstevel@tonic-gate 	short ut_pid;			/* short for compat. - process id */
84*0Sstevel@tonic-gate 	short ut_type;			/* type of entry */
85*0Sstevel@tonic-gate 	struct exit_status ut_exit;	/* The exit status of a process */
86*0Sstevel@tonic-gate 					/* marked as DEAD_PROCESS. */
87*0Sstevel@tonic-gate 	time_t ut_time;			/* time entry was made */
88*0Sstevel@tonic-gate };
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate #include <sys/types32.h>
91*0Sstevel@tonic-gate #include <inttypes.h>
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate /*
94*0Sstevel@tonic-gate  * This data structure describes the utmp *file* contents using
95*0Sstevel@tonic-gate  * fixed-width data types.  It should only be used by the implementation.
96*0Sstevel@tonic-gate  *
97*0Sstevel@tonic-gate  * Applications should use the getutxent(3c) family of routines to interact
98*0Sstevel@tonic-gate  * with this database.
99*0Sstevel@tonic-gate  */
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate struct futmp {
102*0Sstevel@tonic-gate 	char ut_user[8];		/* User login name */
103*0Sstevel@tonic-gate 	char ut_id[4];			/* /etc/inittab id */
104*0Sstevel@tonic-gate 	char ut_line[12];		/* device name (console, lnxx) */
105*0Sstevel@tonic-gate 	int16_t ut_pid;			/* process id */
106*0Sstevel@tonic-gate 	int16_t ut_type;		/* type of entry */
107*0Sstevel@tonic-gate 	struct {
108*0Sstevel@tonic-gate 		int16_t	e_termination;	/* Process termination status */
109*0Sstevel@tonic-gate 		int16_t e_exit;		/* Process exit status */
110*0Sstevel@tonic-gate 	} ut_exit;			/* The exit status of a process */
111*0Sstevel@tonic-gate 	time32_t ut_time;		/* time entry was made */
112*0Sstevel@tonic-gate };
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
115*0Sstevel@tonic-gate 
116*0Sstevel@tonic-gate /*	Definitions for ut_type						*/
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate #define	EMPTY		0
119*0Sstevel@tonic-gate #define	RUN_LVL		1
120*0Sstevel@tonic-gate #define	BOOT_TIME	2
121*0Sstevel@tonic-gate #define	OLD_TIME	3
122*0Sstevel@tonic-gate #define	NEW_TIME	4
123*0Sstevel@tonic-gate #define	INIT_PROCESS	5	/* Process spawned by "init" */
124*0Sstevel@tonic-gate #define	LOGIN_PROCESS	6	/* A "getty" process waiting for login */
125*0Sstevel@tonic-gate #define	USER_PROCESS	7	/* A user process */
126*0Sstevel@tonic-gate #define	DEAD_PROCESS	8
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate #define	ACCOUNTING	9
131*0Sstevel@tonic-gate #define	DOWN_TIME	10
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate #define	UTMAXTYPE	DOWN_TIME	/* Largest legal value of ut_type */
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate /*	Special strings or formats used in the "ut_line" field when	*/
136*0Sstevel@tonic-gate /*	accounting for something other than a process.			*/
137*0Sstevel@tonic-gate /*	No string for the ut_line field can be more than 11 chars +	*/
138*0Sstevel@tonic-gate /*	a NULL in length.						*/
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate #define	RUNLVL_MSG	"run-level %c"
141*0Sstevel@tonic-gate #define	BOOT_MSG	"system boot"
142*0Sstevel@tonic-gate #define	OTIME_MSG	"old time"
143*0Sstevel@tonic-gate #define	NTIME_MSG	"new time"
144*0Sstevel@tonic-gate #define	PSRADM_MSG	"%03d  %s"	/* processor on or off */
145*0Sstevel@tonic-gate #define	DOWN_MSG	"system down"
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate /*	Define and macro for determing if a normal user wrote the entry */
148*0Sstevel@tonic-gate /*	 and marking the utmpx entry as a normal user */
149*0Sstevel@tonic-gate #define	NONROOT_USR	2
150*0Sstevel@tonic-gate #define	nonuser(ut)	((ut).ut_exit.e_exit == NONROOT_USR ? 1 : 0)
151*0Sstevel@tonic-gate #define	setuser(ut)	((ut).ut_exit.e_exit = NONROOT_USR)
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate #if defined(__STDC__)
155*0Sstevel@tonic-gate extern void endutent(void);
156*0Sstevel@tonic-gate extern struct utmp *getutent(void);
157*0Sstevel@tonic-gate extern struct utmp *getutid(const struct utmp *);
158*0Sstevel@tonic-gate extern struct utmp *getutline(const struct utmp *);
159*0Sstevel@tonic-gate extern struct utmp *pututline(const struct utmp *);
160*0Sstevel@tonic-gate extern void setutent(void);
161*0Sstevel@tonic-gate extern int utmpname(const char *);
162*0Sstevel@tonic-gate #else
163*0Sstevel@tonic-gate extern void endutent();
164*0Sstevel@tonic-gate extern struct utmp *getutent();
165*0Sstevel@tonic-gate extern struct utmp *getutid();
166*0Sstevel@tonic-gate extern struct utmp *getutline();
167*0Sstevel@tonic-gate extern struct utmp *pututline();
168*0Sstevel@tonic-gate extern void setutent();
169*0Sstevel@tonic-gate extern int utmpname();
170*0Sstevel@tonic-gate #endif
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate #ifdef	__cplusplus
175*0Sstevel@tonic-gate }
176*0Sstevel@tonic-gate #endif
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate #endif	/* _UTMP_H */
179