1 /* audit.h -- Auditing support -*- linux-c -*-
3 * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Written by Rickard E. (Rik) Faith <faith@redhat.com>
24 #ifndef _LINUX_AUDIT_H_
25 #define _LINUX_AUDIT_H_
27 /* Request and reply types */
28 #define AUDIT_GET 1000 /* Get status */
29 #define AUDIT_SET 1001 /* Set status (enable/disable/auditd) */
30 #define AUDIT_LIST 1002 /* List filtering rules */
31 #define AUDIT_ADD 1003 /* Add filtering rule */
32 #define AUDIT_DEL 1004 /* Delete filtering rule */
33 #define AUDIT_USER 1005 /* Send a message from user-space */
34 #define AUDIT_LOGIN 1006 /* Define the login id and informaiton */
35 #define AUDIT_KERNEL 2000 /* Asynchronous audit record. NOT A REQUEST. */
38 #define AUDIT_PER_TASK 0x01 /* Apply rule at task creation (not syscall) */
39 #define AUDIT_AT_ENTRY 0x02 /* Apply rule at syscall entry */
40 #define AUDIT_AT_EXIT 0x04 /* Apply rule at syscall exit */
41 #define AUDIT_PREPEND 0x10 /* Prepend to front of list */
44 #define AUDIT_NEVER 0 /* Do not build context if rule matches */
45 #define AUDIT_POSSIBLE 1 /* Build context if rule matches */
46 #define AUDIT_ALWAYS 2 /* Generate audit record if rule matches */
48 /* Rule structure sizes -- if these change, different AUDIT_ADD and
49 * AUDIT_LIST commands must be implemented. */
50 #define AUDIT_MAX_FIELDS 64
51 #define AUDIT_BITMASK_SIZE 64
52 #define AUDIT_WORD(nr) ((__u32)((nr)/32))
53 #define AUDIT_BIT(nr) (1 << ((nr) - AUDIT_WORD(nr)*32))
56 /* These are useful when checking the
57 * task structure at task creation time
58 * (AUDIT_PER_TASK). */
68 #define AUDIT_LOGINUID 9
71 /* These are ONLY useful when checking
72 * at syscall exit time (AUDIT_AT_EXIT). */
73 #define AUDIT_DEVMAJOR 100
74 #define AUDIT_DEVMINOR 101
75 #define AUDIT_INODE 102
76 #define AUDIT_EXIT 103
77 #define AUDIT_SUCCESS 104 /* exit >= 0; value ignored */
79 #define AUDIT_ARG0 200
80 #define AUDIT_ARG1 (AUDIT_ARG0+1)
81 #define AUDIT_ARG2 (AUDIT_ARG0+2)
82 #define AUDIT_ARG3 (AUDIT_ARG0+3)
84 #define AUDIT_NEGATE 0x80000000
89 #define AUDIT_STATUS_ENABLED 0x0001
90 #define AUDIT_STATUS_FAILURE 0x0002
91 #define AUDIT_STATUS_PID 0x0004
92 #define AUDIT_STATUS_RATE_LIMIT 0x0008
93 #define AUDIT_STATUS_BACKLOG_LIMIT 0x0010
94 /* Failure-to-log actions */
95 #define AUDIT_FAIL_SILENT 0
96 #define AUDIT_FAIL_PRINTK 1
97 #define AUDIT_FAIL_PANIC 2
100 struct audit_message
{
106 struct audit_status
{
107 __u32 mask
; /* Bit mask for valid entries */
108 __u32 enabled
; /* 1 = enabled, 0 = disbaled */
109 __u32 failure
; /* Failure-to-log action */
110 __u32 pid
; /* pid of auditd process */
111 __u32 rate_limit
; /* messages rate limit (per second) */
112 __u32 backlog_limit
; /* waiting messages limit */
113 __u32 lost
; /* messages lost */
114 __u32 backlog
; /* messages waiting in queue */
123 struct audit_rule
{ /* for AUDIT_LIST, AUDIT_ADD, and AUDIT_DEL */
124 __u32 flags
; /* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */
125 __u32 action
; /* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */
127 __u32 mask
[AUDIT_BITMASK_SIZE
];
128 __u32 fields
[AUDIT_MAX_FIELDS
];
129 __u32 values
[AUDIT_MAX_FIELDS
];
136 struct audit_context
;
139 #ifdef CONFIG_AUDITSYSCALL
140 /* These are defined in auditsc.c */
142 extern int audit_alloc(struct task_struct
*task
);
143 extern void audit_free(struct task_struct
*task
);
144 extern void audit_syscall_entry(struct task_struct
*task
,
145 int major
, unsigned long a0
, unsigned long a1
,
146 unsigned long a2
, unsigned long a3
);
147 extern void audit_syscall_exit(struct task_struct
*task
, int return_code
);
148 extern void audit_getname(const char *name
);
149 extern void audit_putname(const char *name
);
150 extern void audit_inode(const char *name
, unsigned long ino
, dev_t rdev
);
152 /* Private API (for audit.c only) */
153 extern int audit_receive_filter(int type
, int pid
, int uid
, int seq
,
155 extern void audit_get_stamp(struct audit_context
*ctx
,
156 struct timespec
*t
, int *serial
);
157 extern int audit_set_loginuid(struct audit_context
*ctx
, uid_t loginuid
);
159 #define audit_alloc(t) ({ 0; })
160 #define audit_free(t) do { ; } while (0)
161 #define audit_syscall_entry(t,a,b,c,d,e) do { ; } while (0)
162 #define audit_syscall_exit(t,r) do { ; } while (0)
163 #define audit_getname(n) do { ; } while (0)
164 #define audit_putname(n) do { ; } while (0)
165 #define audit_inode(n,i,d) do { ; } while (0)
169 /* These are defined in audit.c */
171 extern void audit_log(struct audit_context
*ctx
,
172 const char *fmt
, ...)
173 __attribute__((format(printf
,2,3)));
175 extern struct audit_buffer
*audit_log_start(struct audit_context
*ctx
);
176 extern void audit_log_format(struct audit_buffer
*ab
,
177 const char *fmt
, ...)
178 __attribute__((format(printf
,2,3)));
179 extern void audit_log_end(struct audit_buffer
*ab
);
180 extern void audit_log_end_fast(struct audit_buffer
*ab
);
181 extern void audit_log_end_irq(struct audit_buffer
*ab
);
182 extern void audit_log_d_path(struct audit_buffer
*ab
,
184 struct dentry
*dentry
,
185 struct vfsmount
*vfsmnt
);
186 extern int audit_set_rate_limit(int limit
);
187 extern int audit_set_backlog_limit(int limit
);
188 extern int audit_set_enabled(int state
);
189 extern int audit_set_failure(int state
);
191 /* Private API (for auditsc.c only) */
192 extern void audit_send_reply(int pid
, int seq
, int type
,
194 void *payload
, int size
);
195 extern void audit_log_lost(const char *message
);
197 #define audit_log(t,f,...) do { ; } while (0)
198 #define audit_log_start(t) ({ NULL; })
199 #define audit_log_vformat(b,f,a) do { ; } while (0)
200 #define audit_log_format(b,f,...) do { ; } while (0)
201 #define audit_log_end(b) do { ; } while (0)
202 #define audit_log_end_fast(b) do { ; } while (0)
203 #define audit_log_end_irq(b) do { ; } while (0)
204 #define audit_log_d_path(b,p,d,v) do { ; } while (0)
205 #define audit_set_rate_limit(l) do { ; } while (0)
206 #define audit_set_backlog_limit(l) do { ; } while (0)
207 #define audit_set_enabled(s) do { ; } while (0)
208 #define audit_set_failure(s) do { ; } while (0)