2 * Copyright (c) 2004-2009 Apple Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
29 * $P4: //depot/projects/trustedbsd/openbsm/bsm/libbsm.h#50 $
36 * NB: definitions, etc., marked with "OpenSSH compatibility" were introduced
37 * solely to allow OpenSSH to compile; Darwin/Apple code should not use them.
40 #include <sys/types.h>
41 #include <sys/cdefs.h>
43 #include <inttypes.h> /* Required for audit.h. */
44 #include <time.h> /* Required for clock_t on Linux. */
46 #include <bsm/audit.h>
47 #include <bsm/audit_record.h>
52 #include <mach/mach.h> /* audit_token_t */
56 * Size parsed token vectors for execve(2) arguments and environmental
57 * variables. Note: changing these sizes affects the ABI of the token
58 * structure, and as the token structure is often placed in the caller stack,
59 * this is undesirable.
61 #define AUDIT_MAX_ARGS 128
62 #define AUDIT_MAX_ENV 128
65 * Arguments to au_preselect(3).
67 #define AU_PRS_USECACHE 0
68 #define AU_PRS_REREAD 1
70 #define AU_PRS_SUCCESS 1
71 #define AU_PRS_FAILURE 2
72 #define AU_PRS_BOTH (AU_PRS_SUCCESS|AU_PRS_FAILURE)
74 #define AUDIT_EVENT_FILE "/etc/security/audit_event"
75 #define AUDIT_CLASS_FILE "/etc/security/audit_class"
76 #define AUDIT_CONTROL_FILE "/etc/security/audit_control"
77 #define AUDIT_USER_FILE "/etc/security/audit_user"
79 #define DIR_CONTROL_ENTRY "dir"
80 #define DIST_CONTROL_ENTRY "dist"
81 #define FILESZ_CONTROL_ENTRY "filesz"
82 #define FLAGS_CONTROL_ENTRY "flags"
83 #define HOST_CONTROL_ENTRY "host"
84 #define MINFREE_CONTROL_ENTRY "minfree"
85 #define NA_CONTROL_ENTRY "naflags"
86 #define POLICY_CONTROL_ENTRY "policy"
87 #define EXPIRE_AFTER_CONTROL_ENTRY "expire-after"
89 #define AU_CLASS_NAME_MAX 8
90 #define AU_CLASS_DESC_MAX 72
91 #define AU_EVENT_NAME_MAX 30
92 #define AU_EVENT_DESC_MAX 50
93 #define AU_USER_NAME_MAX 50
94 #define AU_LINE_MAX 256
95 #define MAX_AUDITSTRING_LEN 256
96 #define BSM_TEXTBUFSZ MAX_AUDITSTRING_LEN /* OpenSSH compatibility */
99 * Arguments to au_close(3).
101 #define AU_TO_NO_WRITE 0 /* Abandon audit record. */
102 #define AU_TO_WRITE 1 /* Commit audit record. */
105 * Output format flags for au_print_flags_tok().
107 #define AU_OFLAG_NONE 0x0000 /* Default form. */
108 #define AU_OFLAG_RAW 0x0001 /* Raw, numeric form. */
109 #define AU_OFLAG_SHORT 0x0002 /* Short form. */
110 #define AU_OFLAG_XML 0x0004 /* XML form. */
111 #define AU_OFLAG_NORESOLVE 0x0008 /* No user/group name resolution. */
114 struct au_event_ent {
115 au_event_t ae_number;
120 typedef struct au_event_ent au_event_ent_t;
122 struct au_class_ent {
127 typedef struct au_class_ent au_class_ent_t;
134 typedef struct au_user_ent au_user_ent_t;
137 #define ADD_TO_MASK(m, c, sel) do { \
138 if (sel & AU_PRS_SUCCESS) \
139 (m)->am_success |= c; \
140 if (sel & AU_PRS_FAILURE) \
141 (m)->am_failure |= c; \
144 #define SUB_FROM_MASK(m, c, sel) do { \
145 if (sel & AU_PRS_SUCCESS) \
146 (m)->am_success &= ((m)->am_success ^ c); \
147 if (sel & AU_PRS_FAILURE) \
148 (m)->am_failure &= ((m)->am_failure ^ c); \
151 #define ADDMASK(m, v) do { \
152 (m)->am_success |= (v)->am_success; \
153 (m)->am_failure |= (v)->am_failure; \
156 #define SUBMASK(m, v) do { \
157 (m)->am_success &= ((m)->am_success ^ (v)->am_success); \
158 (m)->am_failure &= ((m)->am_failure ^ (v)->am_failure); \
163 typedef struct au_tid32 {
168 typedef struct au_tid64 {
173 typedef struct au_tidaddr32 {
179 typedef struct au_tidaddr64 {
187 * argument value 4 bytes/8 bytes (32-bit/64-bit value)
188 * text length 2 bytes
189 * text N bytes + 1 terminating NULL byte
206 * how to print 1 byte
209 * data items (depends on basic unit)
219 * file access mode 4 bytes
220 * owner user ID 4 bytes
221 * owner group ID 4 bytes
222 * file system ID 4 bytes
224 * device 4 bytes/8 bytes (32-bit/64-bit)
246 * text count null-terminated string(s)
250 char *text[AUDIT_MAX_ARGS];
255 * text count null-terminated string(s)
259 char *text[AUDIT_MAX_ENV];
264 * return value 4 bytes
272 * seconds of time 4 bytes
273 * milliseconds of time 4 bytes
274 * file name length 2 bytes
275 * file pathname N bytes + 1 terminating NULL byte
286 * number groups 2 bytes
287 * group list N * 4 bytes
291 u_int32_t list[AUDIT_MAX_GROUPS];
295 * record byte count 4 bytes
296 * version # 1 byte [2]
298 * event modifier 2 bytes
299 * seconds of time 4 bytes/8 bytes (32-bit/64-bit value)
300 * milliseconds of time 4 bytes/8 bytes (32-bit/64-bit value)
312 * record byte count 4 bytes
313 * version # 1 byte [2]
315 * event modifier 2 bytes
316 * address type/length 1 byte (XXX: actually, 4 bytes)
317 * machine address 4 bytes/16 bytes (IPv4/IPv6 address)
318 * seconds of time 4 bytes/8 bytes (32/64-bits)
319 * nanoseconds of time 4 bytes/8 bytes (32/64-bits)
353 * internet address 4 bytes
361 * internet address 16 bytes
369 * version and ihl 1 byte
370 * type of service 1 byte
377 * source address 4 bytes
378 * destination address 4 bytes
394 * object ID type 1 byte
403 * owner user ID 4 bytes
404 * owner group ID 4 bytes
405 * creator user ID 4 bytes
406 * creator group ID 4 bytes
407 * access mode 4 bytes
408 * slot sequence # 4 bytes
422 * port IP address 2 bytes
438 * path length 2 bytes
439 * path N bytes + 1 terminating NULL byte
448 * effective user ID 4 bytes
449 * effective group ID 4 bytes
450 * real user ID 4 bytes
451 * real group ID 4 bytes
455 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
456 * machine address 4 bytes
482 * effective user ID 4 bytes
483 * effective group ID 4 bytes
484 * real user ID 4 bytes
485 * real group ID 4 bytes
489 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
491 * machine address 16 bytes
516 * error status 1 byte
517 * return value 4 bytes/8 bytes (32-bit/64-bit value)
530 * sequence number 4 bytes
537 * socket type 2 bytes
539 * local Internet address 4 bytes
540 * remote port 2 bytes
541 * remote Internet address 4 bytes
552 * socket type 2 bytes
554 * address type/length 4 bytes
555 * local Internet address 4 bytes/16 bytes (IPv4/IPv6 address)
556 * remote port 4 bytes
557 * address type/length 4 bytes
558 * remote Internet address 4 bytes/16 bytes (IPv4/IPv6 address)
571 * socket family 2 bytes
573 * socket address 4 bytes/16 bytes (IPv4/IPv6 address)
579 } au_socketinet_ex32_t;
588 * socket family 2 bytes
598 * effective user ID 4 bytes
599 * effective group ID 4 bytes
600 * real user ID 4 bytes
601 * real group ID 4 bytes
605 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
606 * machine address 4 bytes
632 * effective user ID 4 bytes
633 * effective group ID 4 bytes
634 * real user ID 4 bytes
635 * real group ID 4 bytes
639 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
641 * machine address 16 bytes
666 * text length 2 bytes
667 * text N bytes + 1 terminating NULL byte
675 * upriv status 1 byte
676 * privstr len 2 bytes
677 * privstr N bytes + 1 (\0 byte)
681 u_int16_t privstrlen;
687 * privtstrlen 2 bytes
688 * privtstr N Bytes + 1
690 * privstr N Bytes + 1
693 u_int16_t privtstrlen;
695 u_int16_t privstrlen;
700 * zonename length 2 bytes
701 * zonename text N bytes + 1 NULL terminator
722 * trailer magic number 2 bytes
723 * record byte count 4 bytes
740 au_execarg_t execarg;
741 au_execenv_t execenv;
746 au_header32_ex_t hdr32_ex;
748 au_header64_ex_t hdr64_ex;
750 au_inaddr_ex_t inaddr_ex;
753 au_ipcperm_t ipcperm;
758 au_proc32ex_t proc32_ex;
760 au_proc64ex_t proc64_ex;
765 au_socket_ex32_t socket_ex32;
766 au_socketinet_ex32_t sockinet_ex32;
767 au_socketunix_t sockunix;
768 au_subject32_t subj32;
769 au_subject32ex_t subj32_ex;
770 au_subject64_t subj64;
771 au_subject64ex_t subj64_ex;
774 au_invalid_t invalid;
776 au_zonename_t zonename;
778 au_privset_t privset;
779 } tt; /* The token is one of the above types */
782 typedef struct tokenstr tokenstr_t;
784 int audit_submit(short au_event, au_id_t auid,
785 char status, int reterr, const char *fmt, ...);
788 * Functions relating to querying audit class information.
790 void setauclass(void);
791 void endauclass(void);
792 struct au_class_ent *getauclassent(void);
793 struct au_class_ent *getauclassent_r(au_class_ent_t *class_int);
794 struct au_class_ent *getauclassnam(const char *name);
795 struct au_class_ent *getauclassnam_r(au_class_ent_t *class_int,
797 struct au_class_ent *getauclassnum(au_class_t class_number);
798 struct au_class_ent *getauclassnum_r(au_class_ent_t *class_int,
799 au_class_t class_number);
802 * Functions relating to querying audit control information.
806 int getacdir(char *name, int len);
808 int getacexpire(int *andflg, time_t *age, size_t *size);
809 int getacfilesz(size_t *size_val);
810 int getacflg(char *auditstr, int len);
811 int getachost(char *auditstr, size_t len);
812 int getacmin(int *min_val);
813 int getacna(char *auditstr, int len);
814 int getacpol(char *auditstr, size_t len);
815 int getauditflagsbin(char *auditstr, au_mask_t *masks);
816 int getauditflagschar(char *auditstr, au_mask_t *masks,
818 int au_preselect(au_event_t event, au_mask_t *mask_p,
820 ssize_t au_poltostr(int policy, size_t maxsize, char *buf);
821 int au_strtopol(const char *polstr, int *policy);
824 * Functions relating to querying audit event information.
826 void setauevent(void);
827 void endauevent(void);
828 struct au_event_ent *getauevent(void);
829 struct au_event_ent *getauevent_r(struct au_event_ent *e);
830 struct au_event_ent *getauevnam(const char *name);
831 struct au_event_ent *getauevnam_r(struct au_event_ent *e,
833 struct au_event_ent *getauevnum(au_event_t event_number);
834 struct au_event_ent *getauevnum_r(struct au_event_ent *e,
835 au_event_t event_number);
836 au_event_t *getauevnonam(const char *event_name);
837 au_event_t *getauevnonam_r(au_event_t *ev,
838 const char *event_name);
841 * Functions relating to querying audit user information.
843 void setauuser(void);
844 void endauuser(void);
845 struct au_user_ent *getauuserent(void);
846 struct au_user_ent *getauuserent_r(struct au_user_ent *u);
847 struct au_user_ent *getauusernam(const char *name);
848 struct au_user_ent *getauusernam_r(struct au_user_ent *u,
850 int au_user_mask(char *username, au_mask_t *mask_p);
851 int getfauditflags(au_mask_t *usremask,
852 au_mask_t *usrdmask, au_mask_t *lastmask);
855 * Functions for reading and printing records and tokens from audit trails.
857 int au_read_rec(FILE *fp, u_char **buf);
858 int au_fetch_tok(tokenstr_t *tok, u_char *buf, int len);
859 //XXX The following interface has different prototype from BSM
860 void au_print_tok(FILE *outfp, tokenstr_t *tok,
861 char *del, char raw, char sfrm);
862 void au_print_flags_tok(FILE *outfp, tokenstr_t *tok,
863 char *del, int oflags);
864 void au_print_tok_xml(FILE *outfp, tokenstr_t *tok,
865 char *del, char raw, char sfrm);
868 * Functions relating to XML output.
870 void au_print_xml_header(FILE *outfp);
871 void au_print_xml_footer(FILE *outfp);
874 * BSM library routines for converting between local and BSM constant spaces.
875 * (Note: some of these are replicated in audit_record.h for the benefit of
876 * the FreeBSD and Mac OS X kernels)
878 int au_bsm_to_domain(u_short bsm_domain, int *local_domainp);
879 int au_bsm_to_errno(u_char bsm_error, int *errorp);
880 int au_bsm_to_fcntl_cmd(u_short bsm_fcntl_cmd, int *local_fcntl_cmdp);
881 int au_bsm_to_socket_type(u_short bsm_socket_type,
882 int *local_socket_typep);
883 u_short au_domain_to_bsm(int local_domain);
884 u_char au_errno_to_bsm(int local_errno);
885 u_short au_fcntl_cmd_to_bsm(int local_fcntl_command);
886 u_short au_socket_type_to_bsm(int local_socket_type);
888 const char *au_strerror(u_char bsm_error);
892 * The remaining APIs are associated with Apple's BSM implementation, in
893 * particular as relates to Mach IPC auditing and triggers passed via Mach
897 #include <sys/appleapiopts.h>
899 /**************************************************************************
900 **************************************************************************
901 ** The following definitions, functions, etc., are NOT officially
902 ** supported: they may be changed or removed in the future. Do not use
903 ** them unless you are prepared to cope with that eventuality.
904 **************************************************************************
905 **************************************************************************/
907 #ifdef __APPLE_API_PRIVATE
908 #define __BSM_INTERNAL_NOTIFY_KEY "com.apple.audit.change"
909 #endif /* __APPLE_API_PRIVATE */
912 * au_get_state() return values
913 * XXX use AUC_* values directly instead (<bsm/audit.h>); AUDIT_OFF and
914 * AUDIT_ON are deprecated and WILL be removed.
916 #ifdef __APPLE_API_PRIVATE
917 #define AUDIT_OFF AUC_NOAUDIT
918 #define AUDIT_ON AUC_AUDITING
919 #endif /* __APPLE_API_PRIVATE */
920 #endif /* !__APPLE__ */
923 * Error return codes for audit_set_terminal_id(), audit_write() and its
924 * brethren. We have 255 (not including kAUNoErr) to play with.
926 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
930 kAUBadParamErr = -66049,
934 kAUMakeSubjectTokErr,
935 kAUWriteSubjectTokErr,
936 kAUWriteCallerTokErr,
938 kAUWriteReturnTokErr,
946 * Error return codes for au_get_state() and/or its private support
947 * functions. These codes are designed to be compatible with the
948 * NOTIFY_STATUS_* codes defined in <notify.h> but non-overlapping.
949 * Any changes to notify(3) may cause these values to change in future.
951 * AU_UNIMPL should never happen unless you've changed your system software
952 * without rebooting. Shame on you.
954 #ifdef __APPLE_API_PRIVATE
955 #define AU_UNIMPL NOTIFY_STATUS_FAILED + 1 /* audit unimplemented */
956 #endif /* __APPLE_API_PRIVATE */
957 #endif /* !__APPLE__ */
961 * XXX This prototype should be in audit_record.h
965 * @summary - au_free_token() deallocates a token_t created by any of
966 * the au_to_*() BSM API functions.
968 * The BSM API generally manages deallocation of token_t objects. However,
969 * if au_write() is passed a bad audit descriptor, the token_t * parameter
970 * will be left untouched. In that case, the caller can deallocate the
971 * token_t using au_free_token() if desired. This is, in fact, what
972 * audit_write() does, in keeping with the existing memory management model
975 * @param tok - A token_t * generated by one of the au_to_*() BSM API
976 * calls. For convenience, tok may be NULL, in which case
977 * au_free_token() returns immediately.
979 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
981 void au_free_token(token_t *tok);
984 * Lightweight check to determine if auditing is enabled. If a client
985 * wants to use this to govern whether an entire series of audit calls
986 * should be made--as in the common case of a caller building a set of
987 * tokens, then writing them--it should cache the audit status in a local
988 * variable. This call always returns the current state of auditing.
990 * @return - AUC_AUDITING or AUC_NOAUDIT if no error occurred.
991 * Otherwise the function can return any of the errno values defined for
992 * setaudit(2), or AU_UNIMPL if audit does not appear to be supported by
995 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
997 int au_get_state(void);
1000 * Initialize the audit notification. If it has not already been initialized
1001 * it will automatically on the first call of au_get_state().
1003 uint32_t au_notify_initialize(void);
1006 * Cancel audit notification and free the resources associated with it.
1007 * Responsible code that no longer needs to use au_get_state() should call
1010 int au_notify_terminate(void);
1013 /* OpenSSH compatibility */
1014 int cannot_audit(int);
1018 * audit_set_terminal_id()
1020 * @summary - audit_set_terminal_id() fills in an au_tid_t struct, which is
1021 * used in audit session initialization by processes like /usr/bin/login.
1023 * @param tid - A pointer to an au_tid_t struct.
1025 * @return - kAUNoErr on success; kAUBadParamErr if tid is NULL, kAUStatErr
1026 * or kAUSysctlErr if one of the underlying system calls fails (a message
1027 * is sent to the system log in those cases).
1029 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
1031 int audit_set_terminal_id(au_tid_t *tid);
1034 * BEGIN au_write() WRAPPERS
1036 * The following calls all wrap the existing BSM API. They use the
1037 * provided subject information, if any, to construct the subject token
1038 * required for every log message. They use the provided return/error
1039 * value(s), if any, to construct the success/failure indication required
1040 * for every log message. They only permit one "miscellaneous" token,
1041 * which should contain the event-specific logging information mandated by
1044 * All these calls assume the caller has previously determined that
1045 * auditing is enabled by calling au_get_state().
1051 * @summary - audit_write() is the basis for the other audit_write_*()
1052 * calls. Performs a basic write of an audit record (subject, additional
1053 * info, success/failure). Note that this call only permits logging one
1054 * caller-specified token; clients needing to log more flexibly must use
1055 * the existing BSM API (au_open(), et al.) directly.
1057 * Note on memory management: audit_write() guarantees that the token_t *s
1058 * passed to it will be deallocated whether or not the underlying write to
1059 * the audit log succeeded. This addresses an inconsistency in the
1060 * underlying BSM API in which token_t *s are usually but not always
1063 * @param event_code - The code for the event being logged. This should
1064 * be one of the AUE_ values in /usr/include/bsm/audit_uevents.h.
1066 * @param subject - A token_t * generated by au_to_subject(),
1067 * au_to_subject32(), au_to_subject64(), or au_to_me(). If no subject is
1068 * required, subject should be NULL.
1070 * @param misctok - A token_t * generated by one of the au_to_*() BSM API
1071 * calls. This should correspond to the additional information required by
1072 * CAPP for the event being audited. If no additional information is
1073 * required, misctok should be NULL.
1075 * @param retval - The return value to be logged for this event. This
1076 * should be 0 (zero) for success, otherwise the value is event-specific.
1078 * @param errcode - Any error code associated with the return value (e.g.,
1079 * errno or h_errno). If there was no error, errcode should be 0 (zero).
1081 * @return - The status of the call: 0 (zero) on success, else one of the
1082 * kAU*Err values defined above.
1084 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
1086 int audit_write(short event_code, token_t *subject, token_t *misctok,
1087 char retval, int errcode);
1090 * audit_write_success()
1092 * @summary - audit_write_success() records an auditable event that did not
1093 * encounter an error. The interface is designed to require as little
1094 * direct use of the au_to_*() API as possible. It builds a subject token
1095 * from the information passed in and uses that to invoke audit_write().
1096 * A subject, as defined by CAPP, is a process acting on the user's behalf.
1098 * If the subject information is the same as the current process, use
1099 * au_write_success_self().
1101 * @param event_code - The code for the event being logged. This should
1102 * be one of the AUE_ values in /usr/include/bsm/audit_uevents.h.
1104 * @param misctok - A token_t * generated by one of the au_to_*() BSM API
1105 * calls. This should correspond to the additional information required by
1106 * CAPP for the event being audited. If no additional information is
1107 * required, misctok should be NULL.
1109 * @param auid - The subject's audit ID.
1111 * @param euid - The subject's effective user ID.
1113 * @param egid - The subject's effective group ID.
1115 * @param ruid - The subject's real user ID.
1117 * @param rgid - The subject's real group ID.
1119 * @param pid - The subject's process ID.
1121 * @param sid - The subject's session ID.
1123 * @param tid - The subject's terminal ID.
1125 * @return - The status of the call: 0 (zero) on success, else one of the
1126 * kAU*Err values defined above.
1128 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
1130 int audit_write_success(short event_code, token_t *misctok, au_id_t auid,
1131 uid_t euid, gid_t egid, uid_t ruid, gid_t rgid, pid_t pid,
1132 au_asid_t sid, au_tid_t *tid);
1135 * audit_write_success_self()
1137 * @summary - Similar to audit_write_success(), but used when the subject
1138 * (process) is owned and operated by the auditable user him/herself.
1140 * @param event_code - The code for the event being logged. This should
1141 * be one of the AUE_ values in /usr/include/bsm/audit_uevents.h.
1143 * @param misctok - A token_t * generated by one of the au_to_*() BSM API
1144 * calls. This should correspond to the additional information required by
1145 * CAPP for the event being audited. If no additional information is
1146 * required, misctok should be NULL.
1148 * @return - The status of the call: 0 (zero) on success, else one of the
1149 * kAU*Err values defined above.
1151 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
1153 int audit_write_success_self(short event_code, token_t *misctok);
1156 * audit_write_failure()
1158 * @summary - audit_write_failure() records an auditable event that
1159 * encountered an error. The interface is designed to require as little
1160 * direct use of the au_to_*() API as possible. It builds a subject token
1161 * from the information passed in and uses that to invoke audit_write().
1162 * A subject, as defined by CAPP, is a process acting on the user's behalf.
1164 * If the subject information is the same as the current process, use
1165 * au_write_failure_self().
1167 * @param event_code - The code for the event being logged. This should
1168 * be one of the AUE_ values in /usr/include/bsm/audit_uevents.h.
1170 * @param errmsg - A text message providing additional information about
1171 * the event being audited.
1173 * @param errret - A numerical value providing additional information about
1174 * the error. This is intended to store the value of errno or h_errno if
1175 * it's relevant. This can be 0 (zero) if no additional information is
1178 * @param auid - The subject's audit ID.
1180 * @param euid - The subject's effective user ID.
1182 * @param egid - The subject's effective group ID.
1184 * @param ruid - The subject's real user ID.
1186 * @param rgid - The subject's real group ID.
1188 * @param pid - The subject's process ID.
1190 * @param sid - The subject's session ID.
1192 * @param tid - The subject's terminal ID.
1194 * @return - The status of the call: 0 (zero) on success, else one of the
1195 * kAU*Err values defined above.
1197 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
1199 int audit_write_failure(short event_code, char *errmsg, int errret,
1200 au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
1201 pid_t pid, au_asid_t sid, au_tid_t *tid);
1204 * audit_write_failure_self()
1206 * @summary - Similar to audit_write_failure(), but used when the subject
1207 * (process) is owned and operated by the auditable user him/herself.
1209 * @param event_code - The code for the event being logged. This should
1210 * be one of the AUE_ values in /usr/include/bsm/audit_uevents.h.
1212 * @param errmsg - A text message providing additional information about
1213 * the event being audited.
1215 * @param errret - A numerical value providing additional information about
1216 * the error. This is intended to store the value of errno or h_errno if
1217 * it's relevant. This can be 0 (zero) if no additional information is
1220 * @return - The status of the call: 0 (zero) on success, else one of the
1221 * kAU*Err values defined above.
1223 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
1225 int audit_write_failure_self(short event_code, char *errmsg, int errret);
1228 * audit_write_failure_na()
1230 * @summary - audit_write_failure_na() records errors during login. Such
1231 * errors are implicitly non-attributable (i.e., not ascribable to any user).
1233 * @param event_code - The code for the event being logged. This should
1234 * be one of the AUE_ values in /usr/include/bsm/audit_uevents.h.
1236 * @param errmsg - A text message providing additional information about
1237 * the event being audited.
1239 * @param errret - A numerical value providing additional information about
1240 * the error. This is intended to store the value of errno or h_errno if
1241 * it's relevant. This can be 0 (zero) if no additional information is
1244 * @param euid - The subject's effective user ID.
1246 * @param egid - The subject's effective group ID.
1248 * @param pid - The subject's process ID.
1250 * @param tid - The subject's terminal ID.
1252 * @return - The status of the call: 0 (zero) on success, else one of the
1253 * kAU*Err values defined above.
1255 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
1257 int audit_write_failure_na(short event_code, char *errmsg, int errret,
1258 uid_t euid, gid_t egid, pid_t pid, au_tid_t *tid);
1260 /* END au_write() WRAPPERS */
1264 * audit_token_to_au32()
1266 * @summary - Extract information from an audit_token_t, used to identify
1267 * Mach tasks and senders of Mach messages as subjects to the audit system.
1268 * audit_tokent_to_au32() is the only method that should be used to parse
1269 * an audit_token_t, since its internal representation may change over
1270 * time. A pointer parameter may be NULL if that information is not
1273 * @param atoken - the audit token containing the desired information
1275 * @param auidp - Pointer to a uid_t; on return will be set to the task or
1276 * sender's audit user ID
1278 * @param euidp - Pointer to a uid_t; on return will be set to the task or
1279 * sender's effective user ID
1281 * @param egidp - Pointer to a gid_t; on return will be set to the task or
1282 * sender's effective group ID
1284 * @param ruidp - Pointer to a uid_t; on return will be set to the task or
1285 * sender's real user ID
1287 * @param rgidp - Pointer to a gid_t; on return will be set to the task or
1288 * sender's real group ID
1290 * @param pidp - Pointer to a pid_t; on return will be set to the task or
1291 * sender's process ID
1293 * @param asidp - Pointer to an au_asid_t; on return will be set to the
1294 * task or sender's audit session ID
1296 * @param tidp - Pointer to an au_tid_t; on return will be set to the task
1297 * or sender's terminal ID
1299 * XXXRW: In Apple's bsm-8, these are marked __APPLE_API_PRIVATE.
1301 void audit_token_to_au32(
1302 audit_token_t atoken,
1311 #endif /* !__APPLE__ */
1314 * Wrapper functions to auditon(2).
1316 int audit_get_car(char *path, size_t sz);
1317 int audit_get_class(au_evclass_map_t *evc_map, size_t sz);
1318 int audit_set_class(au_evclass_map_t *evc_map, size_t sz);
1319 int audit_get_cond(int *cond);
1320 int audit_set_cond(int *cond);
1321 int audit_get_cwd(char *path, size_t sz);
1322 int audit_get_fsize(au_fstat_t *fstat, size_t sz);
1323 int audit_set_fsize(au_fstat_t *fstat, size_t sz);
1324 int audit_get_kmask(au_mask_t *kmask, size_t sz);
1325 int audit_set_kmask(au_mask_t *kmask, size_t sz);
1326 int audit_get_kaudit(auditinfo_addr_t *aia, size_t sz);
1327 int audit_set_kaudit(auditinfo_addr_t *aia, size_t sz);
1328 int audit_set_pmask(auditpinfo_t *api, size_t sz);
1329 int audit_get_pinfo(auditpinfo_t *api, size_t sz);
1330 int audit_get_pinfo_addr(auditpinfo_addr_t *apia, size_t sz);
1331 int audit_get_policy(int *policy);
1332 int audit_set_policy(int *policy);
1333 int audit_get_qctrl(au_qctrl_t *qctrl, size_t sz);
1334 int audit_set_qctrl(au_qctrl_t *qctrl, size_t sz);
1335 int audit_get_sinfo_addr(auditinfo_addr_t *aia, size_t sz);
1336 int audit_get_stat(au_stat_t *stats, size_t sz);
1337 int audit_set_stat(au_stat_t *stats, size_t sz);
1338 int audit_send_trigger(int *trigger);
1342 #endif /* !_LIBBSM_H_ */