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