···11+/*-
22+ * Copyright (c) 2009 Apple Inc.
33+ * All rights reserved.
44+ *
55+ * Redistribution and use in source and binary forms, with or without
66+ * modification, are permitted provided that the following conditions
77+ * are met:
88+ * 1. Redistributions of source code must retain the above copyright
99+ * notice, this list of conditions and the following disclaimer.
1010+ * 2. Redistributions in binary form must reproduce the above copyright
1111+ * notice, this list of conditions and the following disclaimer in the
1212+ * documentation and/or other materials provided with the distribution.
1313+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
1414+ * its contributors may be used to endorse or promote products derived
1515+ * from this software without specific prior written permission.
1616+ *
1717+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
1818+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2020+ * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
2121+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2222+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2424+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2525+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
2626+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2727+ * POSSIBILITY OF SUCH DAMAGE.
2828+ *
2929+ * $P4: //depot/projects/trustedbsd/openbsm/bsm/auditd_lib.h#4 $
3030+ */
3131+3232+#ifndef _BSM_AUDIT_SESSION_H_
3333+#define _BSM_AUDIT_SESSION_H_
3434+3535+#include <inttypes.h> /* Required for audit.h. */
3636+#include <stdio.h> /* Required for FILE. */
3737+3838+#include <bsm/audit.h>
3939+#include <bsm/audit_kevents.h> /* Required for AUE_SESSION_* event def's. */
4040+4141+#include <os/availability.h>
4242+4343+/* Defined audit session flags for the ai_flags member of auditinfo_addr.
4444+ * These are opaque to XNU itself, although some may be of interest to certain
4545+ * kernel extensions, notably AU_SESSION_FLAG_HAS_CONSOLE_ACCESS.
4646+ */
4747+enum audit_session_flags {
4848+ /* The initial session created by PID 1. */
4949+ AU_SESSION_FLAG_IS_INITIAL = 0x0001,
5050+5151+ /* The graphics subsystem (CoreGraphics, etc.) is available. */
5252+ AU_SESSION_FLAG_HAS_GRAPHIC_ACCESS = 0x0010,
5353+5454+ /* /dev/tty is available. */
5555+ AU_SESSION_FLAG_HAS_TTY = 0x0020,
5656+5757+ /* The session was created for a remote connection. */
5858+ AU_SESSION_FLAG_IS_REMOTE = 0x1000,
5959+6060+ /* The console and associated devices are available. */
6161+ AU_SESSION_FLAG_HAS_CONSOLE_ACCESS = 0x2000,
6262+6363+ /* An active, authenticated user is associated with the session. */
6464+ AU_SESSION_FLAG_HAS_AUTHENTICATED = 0x4000,
6565+};
6666+6767+/*
6868+ * Audit session device.
6969+ */
7070+7171+#define AUDIT_SDEV_PATH "/dev/auditsessions"
7272+7373+/*
7474+ * au_sdev_open() flags
7575+ */
7676+enum au_sdev_open_flags {
7777+ /* Set audit session device to not to block on reads. */
7878+ AU_SDEVF_NONBLOCK = 0x00000001,
7979+8080+8181+ /* Allow process to monitor all session. (Requires privilege.) */
8282+ AU_SDEVF_ALLSESSIONS = 0x00010000,
8383+};
8484+8585+__BEGIN_DECLS
8686+/*
8787+ * Audit session device handle.
8888+ */
8989+typedef struct au_sdev_handle {
9090+ FILE *ash_fp;
9191+ u_char *ash_buf;
9292+ int ash_reclen;
9393+ int ash_bytesread;
9494+} au_sdev_handle_t;
9595+9696+/*
9797+ * au_sdev_open()
9898+ *
9999+ * @summary - Open the audit session pseudo device.
100100+ *
101101+ * @param flags - Flags that change the behavior of the device. The flags
102102+ * specified are formed by or'ing the following flag: AU_SDEVF_NONBLOCK for
103103+ * non-blocking I/O and AU_SDEF_ALLSESSIONS for monitoring all the sessions
104104+ * and not just the session of the current process.
105105+ *
106106+ * @return Upon success returns the audit session device handle. Otherwise,
107107+ * NULL is returned and the errno is set to indicate the error.
108108+ */
109109+au_sdev_handle_t *au_sdev_open(int flags)
110110+ API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios, watchos, tvos);
111111+112112+/*
113113+ * au_sdev_close()
114114+ *
115115+ * @summary - Close the audit session pseudo device.
116116+ *
117117+ * @param ash - Audit session device handle.
118118+ *
119119+ * @return Upon successful completion 0 is returned. Otherwise, errno is set
120120+ * to indicate the error.
121121+ */
122122+int au_sdev_close(au_sdev_handle_t *ash)
123123+ API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios, watchos, tvos);
124124+125125+/*
126126+ * au_sdev_fd()
127127+ *
128128+ * @summary - Get the file descriptor for the audit session device.
129129+ *
130130+ * @param ash - Audit session device handle.
131131+ *
132132+ * @return File descriptor of the audit session device.
133133+ */
134134+int au_sdev_fd(au_sdev_handle_t *ash)
135135+ API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios, watchos, tvos);
136136+137137+/*
138138+ * au_sdev_read_aia()
139139+ *
140140+ * @summary - Read a session event and an auditinfo_addr record from kernel.
141141+ *
142142+ * @param ash - Audit session device handle.
143143+ *
144144+ * @param event - A pointer to an integer that will contain the event type:
145145+ * AUE_SESSION_START (start of a new session), AUE_SESSION_UPDATE (the
146146+ * session information has been changed), AUE_SESSION_END (all the processes in
147147+ * the session have exited), and AUE_SESSION_CLOSE (the session record has been
148148+ * removed from the kernel).
149149+ *
150150+ * @param aia_p - A pointer to an auditinfo_addr structure that will contain the
151151+ * audit session information on a successful return. The audit masks fields
152152+ * (ai_mask), however, does not currently contain correct informaiton.
153153+ *
154154+ * @return Upon sucessful completetion 0 is returned and the event and aia_p
155155+ * parameters will be populated. Otherwise, errno is set to indicate the error.
156156+ */
157157+int au_sdev_read_aia(au_sdev_handle_t *ash, int *event, auditinfo_addr_t *aia_p)
158158+ API_AVAILABLE(macos(10.8)) API_UNAVAILABLE(ios, watchos, tvos);
159159+160160+__END_DECLS
161161+162162+#endif /* !_BSM_AUDIT_SESSION_H_ */