Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* audit.h -- Auditing support -*- linux-c -*- |
| 2 | * |
| 3 | * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. |
| 4 | * All Rights Reserved. |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
| 19 | * |
| 20 | * Written by Rickard E. (Rik) Faith <faith@redhat.com> |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #ifndef _LINUX_AUDIT_H_ |
| 25 | #define _LINUX_AUDIT_H_ |
| 26 | |
| 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. */ |
| 36 | |
| 37 | /* Rule flags */ |
| 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 */ |
| 42 | |
| 43 | /* Rule actions */ |
| 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 */ |
| 47 | |
| 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)) |
| 54 | |
| 55 | /* Rule fields */ |
| 56 | /* These are useful when checking the |
| 57 | * task structure at task creation time |
| 58 | * (AUDIT_PER_TASK). */ |
| 59 | #define AUDIT_PID 0 |
| 60 | #define AUDIT_UID 1 |
| 61 | #define AUDIT_EUID 2 |
| 62 | #define AUDIT_SUID 3 |
| 63 | #define AUDIT_FSUID 4 |
| 64 | #define AUDIT_GID 5 |
| 65 | #define AUDIT_EGID 6 |
| 66 | #define AUDIT_SGID 7 |
| 67 | #define AUDIT_FSGID 8 |
| 68 | #define AUDIT_LOGINUID 9 |
| 69 | #define AUDIT_PERS 10 |
| 70 | |
| 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 */ |
| 78 | |
| 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) |
| 83 | |
| 84 | #define AUDIT_NEGATE 0x80000000 |
| 85 | |
| 86 | |
| 87 | /* Status symbols */ |
| 88 | /* Mask values */ |
| 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 |
| 98 | |
| 99 | #ifndef __KERNEL__ |
| 100 | struct audit_message { |
| 101 | struct nlmsghdr nlh; |
| 102 | char data[1200]; |
| 103 | }; |
| 104 | #endif |
| 105 | |
| 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 */ |
| 115 | }; |
| 116 | |
| 117 | struct audit_rule { /* for AUDIT_LIST, AUDIT_ADD, and AUDIT_DEL */ |
| 118 | __u32 flags; /* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */ |
| 119 | __u32 action; /* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */ |
| 120 | __u32 field_count; |
| 121 | __u32 mask[AUDIT_BITMASK_SIZE]; |
| 122 | __u32 fields[AUDIT_MAX_FIELDS]; |
| 123 | __u32 values[AUDIT_MAX_FIELDS]; |
| 124 | }; |
| 125 | |
| 126 | #ifdef __KERNEL__ |
| 127 | |
| 128 | struct audit_buffer; |
| 129 | struct audit_context; |
| 130 | struct inode; |
| 131 | |
| 132 | #ifdef CONFIG_AUDITSYSCALL |
| 133 | /* These are defined in auditsc.c */ |
| 134 | /* Public API */ |
| 135 | extern int audit_alloc(struct task_struct *task); |
| 136 | extern void audit_free(struct task_struct *task); |
| 137 | extern void audit_syscall_entry(struct task_struct *task, |
| 138 | int major, unsigned long a0, unsigned long a1, |
| 139 | unsigned long a2, unsigned long a3); |
| 140 | extern void audit_syscall_exit(struct task_struct *task, int return_code); |
| 141 | extern void audit_getname(const char *name); |
| 142 | extern void audit_putname(const char *name); |
| 143 | extern void audit_inode(const char *name, const struct inode *inode); |
| 144 | |
| 145 | /* Private API (for audit.c only) */ |
| 146 | extern int audit_receive_filter(int type, int pid, int uid, int seq, |
| 147 | void *data); |
| 148 | extern void audit_get_stamp(struct audit_context *ctx, |
| 149 | struct timespec *t, int *serial); |
| 150 | extern int audit_set_loginuid(struct audit_context *ctx, uid_t loginuid); |
| 151 | extern uid_t audit_get_loginuid(struct audit_context *ctx); |
| 152 | extern int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode); |
| 153 | #else |
| 154 | #define audit_alloc(t) ({ 0; }) |
| 155 | #define audit_free(t) do { ; } while (0) |
| 156 | #define audit_syscall_entry(t,a,b,c,d,e) do { ; } while (0) |
| 157 | #define audit_syscall_exit(t,r) do { ; } while (0) |
| 158 | #define audit_getname(n) do { ; } while (0) |
| 159 | #define audit_putname(n) do { ; } while (0) |
| 160 | #define audit_inode(n,i) do { ; } while (0) |
| 161 | #define audit_get_loginuid(c) ({ -1; }) |
| 162 | #define audit_ipc_perms(q,u,g,m) ({ 0; }) |
| 163 | #endif |
| 164 | |
| 165 | #ifdef CONFIG_AUDIT |
| 166 | /* These are defined in audit.c */ |
| 167 | /* Public API */ |
| 168 | extern void audit_log(struct audit_context *ctx, |
| 169 | const char *fmt, ...) |
| 170 | __attribute__((format(printf,2,3))); |
| 171 | |
| 172 | extern struct audit_buffer *audit_log_start(struct audit_context *ctx); |
| 173 | extern void audit_log_format(struct audit_buffer *ab, |
| 174 | const char *fmt, ...) |
| 175 | __attribute__((format(printf,2,3))); |
| 176 | extern void audit_log_end(struct audit_buffer *ab); |
| 83c7d09 | 2005-04-29 15:54:44 +0100 | [diff] [blame^] | 177 | extern void audit_log_hex(struct audit_buffer *ab, |
| 178 | const unsigned char *buf, |
| 179 | size_t len); |
| 180 | extern void audit_log_untrustedstring(struct audit_buffer *ab, |
| 181 | const char *string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | extern void audit_log_d_path(struct audit_buffer *ab, |
| 183 | const char *prefix, |
| 184 | struct dentry *dentry, |
| 185 | struct vfsmount *vfsmnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* Private API (for auditsc.c only) */ |
| 187 | extern void audit_send_reply(int pid, int seq, int type, |
| 188 | int done, int multi, |
| 189 | void *payload, int size); |
| 190 | extern void audit_log_lost(const char *message); |
| 191 | #else |
| 192 | #define audit_log(t,f,...) do { ; } while (0) |
| 193 | #define audit_log_start(t) ({ NULL; }) |
| 194 | #define audit_log_vformat(b,f,a) do { ; } while (0) |
| 195 | #define audit_log_format(b,f,...) do { ; } while (0) |
| 196 | #define audit_log_end(b) do { ; } while (0) |
| 83c7d09 | 2005-04-29 15:54:44 +0100 | [diff] [blame^] | 197 | #define audit_log_hex(a,b,l) do { ; } while (0) |
| 198 | #define audit_log_untrustedstring(a,s) do { ; } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | #define audit_log_d_path(b,p,d,v) do { ; } while (0) |
| 200 | #endif |
| 201 | #endif |
| 202 | #endif |