audit.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*-
  2. * SPDX-License-Identifier: BSD-3-Clause
  3. *
  4. * Copyright (c) 2005-2009 Apple Inc.
  5. * Copyright (c) 2016 Robert N. M. Watson
  6. * All rights reserved.
  7. *
  8. * Portions of this software were developed by BAE Systems, the University of
  9. * Cambridge Computer Laboratory, and Memorial University under DARPA/AFRL
  10. * contract FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent
  11. * Computing (TC) research program.
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. *
  17. * 1. Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the distribution.
  22. * 3. Neither the name of Apple Inc. ("Apple") nor the names of
  23. * its contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  27. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  28. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  30. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  31. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  32. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  33. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  35. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #ifndef _BSM_AUDIT_H
  38. #define _BSM_AUDIT_H
  39. #include <sys/param.h>
  40. #include <sys/types.h>
  41. #define AUDIT_RECORD_MAGIC 0x828a0f1b
  42. #define MAX_AUDIT_RECORDS 20
  43. #define MAXAUDITDATA (0x8000 - 1)
  44. #define MAX_AUDIT_RECORD_SIZE MAXAUDITDATA
  45. #define MIN_AUDIT_FILE_SIZE (512 * 1024)
  46. /*
  47. * Minimum noumber of free blocks on the filesystem containing the audit
  48. * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0
  49. * as the kernel does an unsigned compare, plus we want to leave a few blocks
  50. * free so userspace can terminate the log, etc.
  51. */
  52. #define AUDIT_HARD_LIMIT_FREE_BLOCKS 4
  53. /*
  54. * Triggers for the audit daemon.
  55. */
  56. #define AUDIT_TRIGGER_MIN 1
  57. #define AUDIT_TRIGGER_LOW_SPACE 1 /* Below low watermark. */
  58. #define AUDIT_TRIGGER_ROTATE_KERNEL 2 /* Kernel requests rotate. */
  59. #define AUDIT_TRIGGER_READ_FILE 3 /* Re-read config file. */
  60. #define AUDIT_TRIGGER_CLOSE_AND_DIE 4 /* Terminate audit. */
  61. #define AUDIT_TRIGGER_NO_SPACE 5 /* Below min free space. */
  62. #define AUDIT_TRIGGER_ROTATE_USER 6 /* User requests rotate. */
  63. #define AUDIT_TRIGGER_INITIALIZE 7 /* User initialize of auditd. */
  64. #define AUDIT_TRIGGER_EXPIRE_TRAILS 8 /* User expiration of trails. */
  65. #define AUDIT_TRIGGER_MAX 8
  66. /*
  67. * The special device filename (FreeBSD).
  68. */
  69. #define AUDITDEV_FILENAME "audit"
  70. #define AUDIT_TRIGGER_FILE ("/dev/" AUDITDEV_FILENAME)
  71. /*
  72. * Pre-defined audit IDs
  73. */
  74. #define AU_DEFAUDITID (uid_t)(-1)
  75. #define AU_DEFAUDITSID 0
  76. #define AU_ASSIGN_ASID -1
  77. /*
  78. * IPC types.
  79. */
  80. #define AT_IPC_MSG ((u_char)1) /* Message IPC id. */
  81. #define AT_IPC_SEM ((u_char)2) /* Semaphore IPC id. */
  82. #define AT_IPC_SHM ((u_char)3) /* Shared mem IPC id. */
  83. /*
  84. * Audit conditions.
  85. */
  86. #define AUC_UNSET 0
  87. #define AUC_AUDITING 1
  88. #define AUC_NOAUDIT 2
  89. #define AUC_DISABLED -1
  90. /*
  91. * auditon(2) commands.
  92. */
  93. #define A_OLDGETPOLICY 2
  94. #define A_OLDSETPOLICY 3
  95. #define A_GETKMASK 4
  96. #define A_SETKMASK 5
  97. #define A_OLDGETQCTRL 6
  98. #define A_OLDSETQCTRL 7
  99. #define A_GETCWD 8
  100. #define A_GETCAR 9
  101. #define A_GETSTAT 12
  102. #define A_SETSTAT 13
  103. #define A_SETUMASK 14
  104. #define A_SETSMASK 15
  105. #define A_OLDGETCOND 20
  106. #define A_OLDSETCOND 21
  107. #define A_GETCLASS 22
  108. #define A_SETCLASS 23
  109. #define A_GETPINFO 24
  110. #define A_SETPMASK 25
  111. #define A_SETFSIZE 26
  112. #define A_GETFSIZE 27
  113. #define A_GETPINFO_ADDR 28
  114. #define A_GETKAUDIT 29
  115. #define A_SETKAUDIT 30
  116. #define A_SENDTRIGGER 31
  117. #define A_GETSINFO_ADDR 32
  118. #define A_GETPOLICY 33
  119. #define A_SETPOLICY 34
  120. #define A_GETQCTRL 35
  121. #define A_SETQCTRL 36
  122. #define A_GETCOND 37
  123. #define A_SETCOND 38
  124. #define A_GETEVENT 39 /* Get audit event-to-name mapping. */
  125. #define A_SETEVENT 40 /* Set audit event-to-name mapping. */
  126. /*
  127. * Audit policy controls.
  128. */
  129. #define AUDIT_CNT 0x0001
  130. #define AUDIT_AHLT 0x0002
  131. #define AUDIT_ARGV 0x0004
  132. #define AUDIT_ARGE 0x0008
  133. #define AUDIT_SEQ 0x0010
  134. #define AUDIT_WINDATA 0x0020
  135. #define AUDIT_USER 0x0040
  136. #define AUDIT_GROUP 0x0080
  137. #define AUDIT_TRAIL 0x0100
  138. #define AUDIT_PATH 0x0200
  139. #define AUDIT_SCNT 0x0400
  140. #define AUDIT_PUBLIC 0x0800
  141. #define AUDIT_ZONENAME 0x1000
  142. #define AUDIT_PERZONE 0x2000
  143. /*
  144. * Default audit queue control parameters.
  145. */
  146. #define AQ_HIWATER 100
  147. #define AQ_MAXHIGH 10000
  148. #define AQ_LOWATER 10
  149. #define AQ_BUFSZ MAXAUDITDATA
  150. #define AQ_MAXBUFSZ 1048576
  151. /*
  152. * Default minimum percentage free space on file system.
  153. */
  154. #define AU_FS_MINFREE 20
  155. /*
  156. * Type definitions used indicating the length of variable length addresses
  157. * in tokens containing addresses, such as header fields.
  158. */
  159. #define AU_IPv4 4
  160. #define AU_IPv6 16
  161. __BEGIN_DECLS
  162. typedef uid_t au_id_t;
  163. typedef pid_t au_asid_t;
  164. typedef u_int16_t au_event_t;
  165. typedef u_int16_t au_emod_t;
  166. typedef u_int32_t au_class_t;
  167. typedef u_int64_t au_asflgs_t __attribute__ ((aligned (8)));
  168. struct au_tid {
  169. u_int32_t port; /* XXX dev_t compatibility */
  170. u_int32_t machine;
  171. };
  172. typedef struct au_tid au_tid_t;
  173. struct au_tid_addr {
  174. u_int32_t at_port; /* XXX dev_t compatibility */
  175. u_int32_t at_type;
  176. u_int32_t at_addr[4];
  177. };
  178. typedef struct au_tid_addr au_tid_addr_t;
  179. struct au_mask {
  180. unsigned int am_success; /* Success bits. */
  181. unsigned int am_failure; /* Failure bits. */
  182. };
  183. typedef struct au_mask au_mask_t;
  184. struct auditinfo {
  185. au_id_t ai_auid; /* Audit user ID. */
  186. au_mask_t ai_mask; /* Audit masks. */
  187. au_tid_t ai_termid; /* Terminal ID. */
  188. au_asid_t ai_asid; /* Audit session ID. */
  189. };
  190. typedef struct auditinfo auditinfo_t;
  191. struct auditinfo_addr {
  192. au_id_t ai_auid; /* Audit user ID. */
  193. au_mask_t ai_mask; /* Audit masks. */
  194. au_tid_addr_t ai_termid; /* Terminal ID. */
  195. au_asid_t ai_asid; /* Audit session ID. */
  196. au_asflgs_t ai_flags; /* Audit session flags. */
  197. };
  198. typedef struct auditinfo_addr auditinfo_addr_t;
  199. struct auditpinfo {
  200. pid_t ap_pid; /* ID of target process. */
  201. au_id_t ap_auid; /* Audit user ID. */
  202. au_mask_t ap_mask; /* Audit masks. */
  203. au_tid_t ap_termid; /* Terminal ID. */
  204. au_asid_t ap_asid; /* Audit session ID. */
  205. };
  206. typedef struct auditpinfo auditpinfo_t;
  207. struct auditpinfo_addr {
  208. pid_t ap_pid; /* ID of target process. */
  209. au_id_t ap_auid; /* Audit user ID. */
  210. au_mask_t ap_mask; /* Audit masks. */
  211. au_tid_addr_t ap_termid; /* Terminal ID. */
  212. au_asid_t ap_asid; /* Audit session ID. */
  213. au_asflgs_t ap_flags; /* Audit session flags. */
  214. };
  215. typedef struct auditpinfo_addr auditpinfo_addr_t;
  216. struct au_session {
  217. auditinfo_addr_t *as_aia_p; /* Ptr to full audit info. */
  218. au_mask_t as_mask; /* Process Audit Masks. */
  219. };
  220. typedef struct au_session au_session_t;
  221. /*
  222. * Contents of token_t are opaque outside of libbsm.
  223. */
  224. typedef struct au_token token_t;
  225. /*
  226. * Kernel audit queue control parameters:
  227. * Default: Maximum:
  228. * aq_hiwater: AQ_HIWATER (100) AQ_MAXHIGH (10000)
  229. * aq_lowater: AQ_LOWATER (10) <aq_hiwater
  230. * aq_bufsz: AQ_BUFSZ (32767) AQ_MAXBUFSZ (1048576)
  231. * aq_delay: 20 20000 (not used)
  232. */
  233. struct au_qctrl {
  234. int aq_hiwater; /* Max # of audit recs in queue when */
  235. /* threads with new ARs get blocked. */
  236. int aq_lowater; /* # of audit recs in queue when */
  237. /* blocked threads get unblocked. */
  238. int aq_bufsz; /* Max size of audit record for audit(2). */
  239. int aq_delay; /* Queue delay (not used). */
  240. int aq_minfree; /* Minimum filesystem percent free space. */
  241. };
  242. typedef struct au_qctrl au_qctrl_t;
  243. /*
  244. * Structure for the audit statistics.
  245. */
  246. struct audit_stat {
  247. unsigned int as_version;
  248. unsigned int as_numevent;
  249. int as_generated;
  250. int as_nonattrib;
  251. int as_kernel;
  252. int as_audit;
  253. int as_auditctl;
  254. int as_enqueue;
  255. int as_written;
  256. int as_wblocked;
  257. int as_rblocked;
  258. int as_dropped;
  259. int as_totalsize;
  260. unsigned int as_memused;
  261. };
  262. typedef struct audit_stat au_stat_t;
  263. /*
  264. * Structure for the audit file statistics.
  265. */
  266. struct audit_fstat {
  267. u_int64_t af_filesz;
  268. u_int64_t af_currsz;
  269. };
  270. typedef struct audit_fstat au_fstat_t;
  271. /*
  272. * Audit to event class mapping.
  273. */
  274. struct au_evclass_map {
  275. au_event_t ec_number;
  276. au_class_t ec_class;
  277. };
  278. typedef struct au_evclass_map au_evclass_map_t;
  279. /*
  280. * Event-to-name mapping.
  281. */
  282. #define EVNAMEMAP_NAME_SIZE 64
  283. struct au_evname_map {
  284. au_event_t en_number;
  285. char en_name[EVNAMEMAP_NAME_SIZE];
  286. };
  287. typedef struct au_evname_map au_evname_map_t;
  288. /*
  289. * Audit system calls.
  290. */
  291. #if !defined(_KERNEL) && !defined(KERNEL)
  292. int audit(const void *, int);
  293. int auditon(int, void *, int);
  294. int auditctl(const char *);
  295. int getauid(au_id_t *);
  296. int setauid(const au_id_t *);
  297. int getaudit(struct auditinfo *);
  298. int setaudit(const struct auditinfo *);
  299. int getaudit_addr(struct auditinfo_addr *, int);
  300. int setaudit_addr(const struct auditinfo_addr *, int);
  301. #ifdef __APPLE_API_PRIVATE
  302. #include <mach/port.h>
  303. mach_port_name_t audit_session_self(void);
  304. au_asid_t audit_session_join(mach_port_name_t port);
  305. #endif /* __APPLE_API_PRIVATE */
  306. #endif /* defined(_KERNEL) || defined(KERNEL) */
  307. __END_DECLS
  308. #endif /* !_BSM_AUDIT_H */