audit.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. #ifndef _LINUX_AUDIT_H_
  24. #define _LINUX_AUDIT_H_
  25. /* Request and reply types */
  26. #define AUDIT_GET 1000 /* Get status */
  27. #define AUDIT_SET 1001 /* Set status (enable/disable/auditd) */
  28. #define AUDIT_LIST 1002 /* List filtering rules */
  29. #define AUDIT_ADD 1003 /* Add filtering rule */
  30. #define AUDIT_DEL 1004 /* Delete filtering rule */
  31. #define AUDIT_USER 1005 /* Send a message from user-space */
  32. #define AUDIT_LOGIN 1006 /* Define the login id and informaiton */
  33. #define AUDIT_KERNEL 2000 /* Asynchronous audit record. NOT A REQUEST. */
  34. /* Rule flags */
  35. #define AUDIT_PER_TASK 0x01 /* Apply rule at task creation (not syscall) */
  36. #define AUDIT_AT_ENTRY 0x02 /* Apply rule at syscall entry */
  37. #define AUDIT_AT_EXIT 0x04 /* Apply rule at syscall exit */
  38. #define AUDIT_PREPEND 0x10 /* Prepend to front of list */
  39. /* Rule actions */
  40. #define AUDIT_NEVER 0 /* Do not build context if rule matches */
  41. #define AUDIT_POSSIBLE 1 /* Build context if rule matches */
  42. #define AUDIT_ALWAYS 2 /* Generate audit record if rule matches */
  43. /* Rule structure sizes -- if these change, different AUDIT_ADD and
  44. * AUDIT_LIST commands must be implemented. */
  45. #define AUDIT_MAX_FIELDS 64
  46. #define AUDIT_BITMASK_SIZE 64
  47. #define AUDIT_WORD(nr) ((__u32)((nr)/32))
  48. #define AUDIT_BIT(nr) (1 << ((nr) - AUDIT_WORD(nr)*32))
  49. /* Rule fields */
  50. /* These are useful when checking the
  51. * task structure at task creation time
  52. * (AUDIT_PER_TASK). */
  53. #define AUDIT_PID 0
  54. #define AUDIT_UID 1
  55. #define AUDIT_EUID 2
  56. #define AUDIT_SUID 3
  57. #define AUDIT_FSUID 4
  58. #define AUDIT_GID 5
  59. #define AUDIT_EGID 6
  60. #define AUDIT_SGID 7
  61. #define AUDIT_FSGID 8
  62. #define AUDIT_LOGINUID 9
  63. #define AUDIT_PERS 10
  64. /* These are ONLY useful when checking
  65. * at syscall exit time (AUDIT_AT_EXIT). */
  66. #define AUDIT_DEVMAJOR 100
  67. #define AUDIT_DEVMINOR 101
  68. #define AUDIT_INODE 102
  69. #define AUDIT_EXIT 103
  70. #define AUDIT_SUCCESS 104 /* exit >= 0; value ignored */
  71. #define AUDIT_ARG0 200
  72. #define AUDIT_ARG1 (AUDIT_ARG0+1)
  73. #define AUDIT_ARG2 (AUDIT_ARG0+2)
  74. #define AUDIT_ARG3 (AUDIT_ARG0+3)
  75. #define AUDIT_NEGATE 0x80000000
  76. /* Status symbols */
  77. /* Mask values */
  78. #define AUDIT_STATUS_ENABLED 0x0001
  79. #define AUDIT_STATUS_FAILURE 0x0002
  80. #define AUDIT_STATUS_PID 0x0004
  81. #define AUDIT_STATUS_RATE_LIMIT 0x0008
  82. #define AUDIT_STATUS_BACKLOG_LIMIT 0x0010
  83. /* Failure-to-log actions */
  84. #define AUDIT_FAIL_SILENT 0
  85. #define AUDIT_FAIL_PRINTK 1
  86. #define AUDIT_FAIL_PANIC 2
  87. #ifndef __KERNEL__
  88. struct audit_message {
  89. struct nlmsghdr nlh;
  90. char data[1200];
  91. };
  92. #endif
  93. struct audit_status {
  94. __u32 mask; /* Bit mask for valid entries */
  95. __u32 enabled; /* 1 = enabled, 0 = disbaled */
  96. __u32 failure; /* Failure-to-log action */
  97. __u32 pid; /* pid of auditd process */
  98. __u32 rate_limit; /* messages rate limit (per second) */
  99. __u32 backlog_limit; /* waiting messages limit */
  100. __u32 lost; /* messages lost */
  101. __u32 backlog; /* messages waiting in queue */
  102. };
  103. struct audit_rule { /* for AUDIT_LIST, AUDIT_ADD, and AUDIT_DEL */
  104. __u32 flags; /* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */
  105. __u32 action; /* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */
  106. __u32 field_count;
  107. __u32 mask[AUDIT_BITMASK_SIZE];
  108. __u32 fields[AUDIT_MAX_FIELDS];
  109. __u32 values[AUDIT_MAX_FIELDS];
  110. };
  111. #ifdef __KERNEL__
  112. struct audit_buffer;
  113. struct audit_context;
  114. struct inode;
  115. #ifdef CONFIG_AUDITSYSCALL
  116. /* These are defined in auditsc.c */
  117. /* Public API */
  118. extern int audit_alloc(struct task_struct *task);
  119. extern void audit_free(struct task_struct *task);
  120. extern void audit_syscall_entry(struct task_struct *task,
  121. int major, unsigned long a0, unsigned long a1,
  122. unsigned long a2, unsigned long a3);
  123. extern void audit_syscall_exit(struct task_struct *task, int return_code);
  124. extern void audit_getname(const char *name);
  125. extern void audit_putname(const char *name);
  126. extern void audit_inode(const char *name, const struct inode *inode);
  127. /* Private API (for audit.c only) */
  128. extern int audit_receive_filter(int type, int pid, int uid, int seq,
  129. void *data);
  130. extern void audit_get_stamp(struct audit_context *ctx,
  131. struct timespec *t, int *serial);
  132. extern int audit_set_loginuid(struct audit_context *ctx, uid_t loginuid);
  133. extern uid_t audit_get_loginuid(struct audit_context *ctx);
  134. extern int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode);
  135. #else
  136. #define audit_alloc(t) ({ 0; })
  137. #define audit_free(t) do { ; } while (0)
  138. #define audit_syscall_entry(t,a,b,c,d,e) do { ; } while (0)
  139. #define audit_syscall_exit(t,r) do { ; } while (0)
  140. #define audit_getname(n) do { ; } while (0)
  141. #define audit_putname(n) do { ; } while (0)
  142. #define audit_inode(n,i) do { ; } while (0)
  143. #define audit_get_loginuid(c) ({ -1; })
  144. #define audit_ipc_perms(q,u,g,m) ({ 0; })
  145. #endif
  146. #ifdef CONFIG_AUDIT
  147. /* These are defined in audit.c */
  148. /* Public API */
  149. extern void audit_log(struct audit_context *ctx,
  150. const char *fmt, ...)
  151. __attribute__((format(printf,2,3)));
  152. extern struct audit_buffer *audit_log_start(struct audit_context *ctx);
  153. extern void audit_log_format(struct audit_buffer *ab,
  154. const char *fmt, ...)
  155. __attribute__((format(printf,2,3)));
  156. extern void audit_log_end(struct audit_buffer *ab);
  157. extern void audit_log_hex(struct audit_buffer *ab,
  158. const unsigned char *buf,
  159. size_t len);
  160. extern void audit_log_untrustedstring(struct audit_buffer *ab,
  161. const char *string);
  162. extern void audit_log_d_path(struct audit_buffer *ab,
  163. const char *prefix,
  164. struct dentry *dentry,
  165. struct vfsmount *vfsmnt);
  166. /* Private API (for auditsc.c only) */
  167. extern void audit_send_reply(int pid, int seq, int type,
  168. int done, int multi,
  169. void *payload, int size);
  170. extern void audit_log_lost(const char *message);
  171. #else
  172. #define audit_log(t,f,...) do { ; } while (0)
  173. #define audit_log_start(t) ({ NULL; })
  174. #define audit_log_vformat(b,f,a) do { ; } while (0)
  175. #define audit_log_format(b,f,...) do { ; } while (0)
  176. #define audit_log_end(b) do { ; } while (0)
  177. #define audit_log_hex(a,b,l) do { ; } while (0)
  178. #define audit_log_untrustedstring(a,s) do { ; } while (0)
  179. #define audit_log_d_path(b,p,d,v) do { ; } while (0)
  180. #endif
  181. #endif
  182. #endif