]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libulog/ulog.h
Massively extend libulog:
[FreeBSD/FreeBSD.git] / lib / libulog / ulog.h
1 /*-
2  * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _ULOG_H_
30 #define _ULOG_H_
31
32 #include <sys/cdefs.h>
33 #include <sys/_timeval.h>
34 #include <sys/_types.h>
35
36 #ifndef _PID_T_DECLARED
37 typedef __pid_t         pid_t;
38 #define _PID_T_DECLARED
39 #endif
40
41 /*
42  * libulog.
43  *
44  * This library is provided as a migratory tool towards <utmpx.h>.  We
45  * cannot yet implement <utmpx.h>, because our on-disk file format lacks
46  * various fields.  <utmpx.h> also has some shortcomings.  Ideally we
47  * want to allow logging of user login records generated by unprivileged
48  * processes as well, provided that they hold a file descriptor to a
49  * pseudo-terminal master device.
50  *
51  * This library (or at least parts of it) will hopefully deprecate over
52  * time, when we provide the <utmpx.h> API.
53  */
54
55 struct ulog_utmpx {
56         char            ut_user[32];
57         char            ut_id[8];       /* XXX: unsupported. */
58         char            ut_line[32];
59         char            ut_host[256];
60         pid_t           ut_pid;         /* XXX: unsupported. */
61         short           ut_type;
62 #define EMPTY           0
63 #define BOOT_TIME       1
64 #define OLD_TIME        2
65 #define NEW_TIME        3
66 #define USER_PROCESS    4
67 #define INIT_PROCESS    5               /* XXX: unsupported. */
68 #define LOGIN_PROCESS   6               /* XXX: unsupported. */
69 #define DEAD_PROCESS    7
70 #define SHUTDOWN_TIME   8
71         struct timeval  ut_tv;
72 };
73
74 __BEGIN_DECLS
75 /* POSIX routines. */
76 void    ulog_endutxent(void);
77 struct ulog_utmpx *ulog_getutxent(void);
78 #if 0
79 struct ulog_utmpx *ulog_getutxid(const struct ulog_utmpx *);
80 #endif
81 struct ulog_utmpx *ulog_getutxline(const struct ulog_utmpx *);
82 struct ulog_utmpx *ulog_pututxline(const struct ulog_utmpx *);
83 void    ulog_setutxent(void);
84
85 /* Extensions. */
86 struct ulog_utmpx *ulog_getutxuser(const char *);
87 int     ulog_setutxfile(int, const char *);
88 #define UTXF_UTMP       0
89 #define UTXF_WTMP       1
90 #define UTXF_LASTLOG    2
91
92 /* Login/logout utility functions. */
93 void    ulog_login(const char *, const char *, const char *);
94 void    ulog_login_pseudo(int, const char *);
95 void    ulog_logout(const char *);
96 void    ulog_logout_pseudo(int);
97 __END_DECLS
98
99 #ifdef _ULOG_POSIX_NAMES
100 #define utmpx           ulog_utmpx
101 #define endutxent       ulog_endutxent
102 #define getutxent       ulog_getutxent
103 #define getutxline      ulog_getutxline
104 #define pututxline      ulog_pututxline
105 #define setutxent       ulog_setutxent
106 #endif /* _ULOG_POSIX_NAMES */
107
108 #endif /* !_ULOG_H_ */