]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/openbsm/sys/bsm/audit.h
Merge OpenBSM 1.1 alpha 2 from the OpenBSM vendor branch to head, both
[FreeBSD/FreeBSD.git] / contrib / openbsm / sys / bsm / audit.h
1 /*-
2  * Copyright (c) 2005 Apple Inc.
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  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit.h#1 $
30  */
31
32 #ifndef _BSM_AUDIT_H
33 #define _BSM_AUDIT_H
34
35 #define AUDIT_RECORD_MAGIC      0x828a0f1b
36 #define MAX_AUDIT_RECORDS       20
37 #define MAXAUDITDATA            (0x8000 - 1)
38 #define MAX_AUDIT_RECORD_SIZE   MAXAUDITDATA
39 #define MIN_AUDIT_FILE_SIZE     (512 * 1024)
40
41 /*
42  * Triggers for the audit daemon.
43  */
44 #define AUDIT_TRIGGER_MIN               1
45 #define AUDIT_TRIGGER_LOW_SPACE         1       /* Below low watermark. */
46 #define AUDIT_TRIGGER_ROTATE_KERNEL     2       /* Kernel requests rotate. */
47 #define AUDIT_TRIGGER_READ_FILE         3       /* Re-read config file. */
48 #define AUDIT_TRIGGER_CLOSE_AND_DIE     4       /* Terminate audit. */
49 #define AUDIT_TRIGGER_NO_SPACE          5       /* Below min free space. */
50 #define AUDIT_TRIGGER_ROTATE_USER       6       /* User requests roate. */
51 #define AUDIT_TRIGGER_MAX               6
52
53 /*
54  * The special device filename (FreeBSD).
55  */
56 #define AUDITDEV_FILENAME       "audit"
57 #define AUDIT_TRIGGER_FILE      ("/dev/" AUDITDEV_FILENAME)
58
59 /*
60  * Pre-defined audit IDs
61  */
62 #define AU_DEFAUDITID   -1
63
64 /*
65  * IPC types.
66  */
67 #define AT_IPC_MSG      ((u_char)1)     /* Message IPC id. */
68 #define AT_IPC_SEM      ((u_char)2)     /* Semaphore IPC id. */
69 #define AT_IPC_SHM      ((u_char)3)     /* Shared mem IPC id. */
70
71 /*
72  * Audit conditions.
73  */
74 #define AUC_UNSET               0
75 #define AUC_AUDITING            1
76 #define AUC_NOAUDIT             2
77 #define AUC_DISABLED            -1
78
79 /*
80  * auditon(2) commands.
81  */
82 #define A_GETPOLICY     2
83 #define A_SETPOLICY     3
84 #define A_GETKMASK      4
85 #define A_SETKMASK      5
86 #define A_GETQCTRL      6
87 #define A_SETQCTRL      7
88 #define A_GETCWD        8
89 #define A_GETCAR        9
90 #define A_GETSTAT       12
91 #define A_SETSTAT       13
92 #define A_SETUMASK      14
93 #define A_SETSMASK      15
94 #define A_GETCOND       20
95 #define A_SETCOND       21
96 #define A_GETCLASS      22
97 #define A_SETCLASS      23
98 #define A_GETPINFO      24
99 #define A_SETPMASK      25
100 #define A_SETFSIZE      26
101 #define A_GETFSIZE      27
102 #define A_GETPINFO_ADDR 28
103 #define A_GETKAUDIT     29
104 #define A_SETKAUDIT     30
105 #define A_SENDTRIGGER   31
106
107 /*
108  * Audit policy controls.
109  */
110 #define AUDIT_CNT       0x0001
111 #define AUDIT_AHLT      0x0002
112 #define AUDIT_ARGV      0x0004
113 #define AUDIT_ARGE      0x0008
114 #define AUDIT_SEQ       0x0010
115 #define AUDIT_WINDATA   0x0020
116 #define AUDIT_USER      0x0040
117 #define AUDIT_GROUP     0x0080
118 #define AUDIT_TRAIL     0x0100
119 #define AUDIT_PATH      0x0200
120 #define AUDIT_SCNT      0x0400
121 #define AUDIT_PUBLIC    0x0800
122 #define AUDIT_ZONENAME  0x1000
123 #define AUDIT_PERZONE   0x2000
124
125 /*
126  * Default audit queue control parameters.
127  */
128 #define AQ_HIWATER      100
129 #define AQ_MAXHIGH      10000
130 #define AQ_LOWATER      10
131 #define AQ_BUFSZ        MAXAUDITDATA
132 #define AQ_MAXBUFSZ     1048576
133
134 /*
135  * Default minimum percentage free space on file system.
136  */
137 #define AU_FS_MINFREE   20
138
139 /*
140  * Type definitions used indicating the length of variable length addresses
141  * in tokens containing addresses, such as header fields.
142  */
143 #define AU_IPv4         4
144 #define AU_IPv6         16
145
146 __BEGIN_DECLS
147
148 typedef uid_t           au_id_t;
149 typedef pid_t           au_asid_t;
150 typedef u_int16_t       au_event_t;
151 typedef u_int16_t       au_emod_t;
152 typedef u_int32_t       au_class_t;
153
154 struct au_tid {
155         dev_t           port;
156         u_int32_t       machine;
157 };
158 typedef struct au_tid   au_tid_t;
159
160 struct au_tid_addr {
161         dev_t           at_port;
162         u_int32_t       at_type;
163         u_int32_t       at_addr[4];
164 };
165 typedef struct au_tid_addr      au_tid_addr_t;
166
167 struct au_mask {
168         unsigned int    am_success;     /* Success bits. */
169         unsigned int    am_failure;     /* Failure bits. */
170 };
171 typedef struct au_mask  au_mask_t;
172
173 struct auditinfo {
174         au_id_t         ai_auid;        /* Audit user ID. */
175         au_mask_t       ai_mask;        /* Audit masks. */
176         au_tid_t        ai_termid;      /* Terminal ID. */
177         au_asid_t       ai_asid;        /* Audit session ID. */
178 };
179 typedef struct auditinfo        auditinfo_t;
180
181 struct auditinfo_addr {
182         au_id_t         ai_auid;        /* Audit user ID. */
183         au_mask_t       ai_mask;        /* Audit masks. */
184         au_tid_addr_t   ai_termid;      /* Terminal ID. */
185         au_asid_t       ai_asid;        /* Audit session ID. */
186 };
187 typedef struct auditinfo_addr   auditinfo_addr_t;
188
189 struct auditpinfo {
190         pid_t           ap_pid;         /* ID of target process. */
191         au_id_t         ap_auid;        /* Audit user ID. */
192         au_mask_t       ap_mask;        /* Audit masks. */
193         au_tid_t        ap_termid;      /* Terminal ID. */
194         au_asid_t       ap_asid;        /* Audit session ID. */
195 };
196 typedef struct auditpinfo       auditpinfo_t;
197
198 struct auditpinfo_addr {
199         pid_t           ap_pid;         /* ID of target process. */
200         au_id_t         ap_auid;        /* Audit user ID. */
201         au_mask_t       ap_mask;        /* Audit masks. */
202         au_tid_addr_t   ap_termid;      /* Terminal ID. */
203         au_asid_t       ap_asid;        /* Audit session ID. */
204 };
205 typedef struct auditpinfo_addr  auditpinfo_addr_t;
206
207 /*
208  * Contents of token_t are opaque outside of libbsm.
209  */
210 typedef struct au_token token_t;
211
212 /*
213  * Kernel audit queue control parameters.
214  */
215 struct au_qctrl {
216         size_t  aq_hiwater;
217         size_t  aq_lowater;
218         size_t  aq_bufsz;
219         clock_t aq_delay;
220         int     aq_minfree;     /* Minimum filesystem percent free space. */
221 };
222 typedef struct au_qctrl au_qctrl_t;
223
224 /*
225  * Structure for the audit statistics.
226  */
227 struct audit_stat {
228         unsigned int    as_version;
229         unsigned int    as_numevent;
230         int             as_generated;
231         int             as_nonattrib;
232         int             as_kernel;
233         int             as_audit;
234         int             as_auditctl;
235         int             as_enqueue;
236         int             as_written;
237         int             as_wblocked;
238         int             as_rblocked;
239         int             as_dropped;
240         int             as_totalsize;
241         unsigned int    as_memused;
242 };
243 typedef struct audit_stat       au_stat_t;
244
245 /*
246  * Structure for the audit file statistics.
247  */
248 struct audit_fstat {
249         u_quad_t        af_filesz;
250         u_quad_t        af_currsz;
251 };
252 typedef struct audit_fstat      au_fstat_t;
253
254 /*
255  * Audit to event class mapping.
256  */
257 struct au_evclass_map {
258         au_event_t      ec_number;
259         au_class_t      ec_class;
260 };
261 typedef struct au_evclass_map   au_evclass_map_t;
262
263 /*
264  * Audit system calls.
265  */
266 #if !defined(_KERNEL) && !defined(KERNEL)
267 int     audit(const void *, int);
268 int     auditon(int, void *, int);
269 int     auditctl(const char *);
270 int     getauid(au_id_t *);
271 int     setauid(const au_id_t *);
272 int     getaudit(struct auditinfo *);
273 int     setaudit(const struct auditinfo *);
274 int     getaudit_addr(struct auditinfo_addr *, int);
275 int     setaudit_addr(const struct auditinfo_addr *, int);
276 #endif /* defined(_KERNEL) || defined(KERNEL) */
277
278 __END_DECLS
279
280 #endif /* !_BSM_AUDIT_H */