···11+/*
22+ * Copyright (c) 2006-2010 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. Please obtain a copy of the License at
1010+ * http://www.opensource.apple.com/apsl/ and read it before using this
1111+ * file.
1212+ *
1313+ * The Original Code and all software distributed under the License are
1414+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1515+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
1616+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
1717+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
1818+ * Please see the License for the specific language governing rights and
1919+ * limitations under the License.
2020+ *
2121+ * @APPLE_LICENSE_HEADER_END@
2222+ */
2323+#ifndef _SANDBOX_H_
2424+#define _SANDBOX_H_
2525+2626+#include <sys/cdefs.h>
2727+#include <stdint.h>
2828+#include <unistd.h>
2929+3030+__BEGIN_DECLS
3131+/*
3232+ * @function sandbox_init
3333+ * Places the current process in a sandbox with a profile as
3434+ * specified. If the process is already in a sandbox, the new profile
3535+ * is ignored and sandbox_init() returns an error.
3636+ *
3737+ * @param profile (input) The Sandbox profile to be used. The format
3838+ * and meaning of this parameter is modified by the `flags' parameter.
3939+ *
4040+ * @param flags (input) Must be SANDBOX_NAMED. All other
4141+ * values are reserved.
4242+ *
4343+ * @param errorbuf (output) In the event of an error, sandbox_init
4444+ * will set `*errorbuf' to a pointer to a NUL-terminated string
4545+ * describing the error. This string may contain embedded newlines.
4646+ * This error information is suitable for developers and is not
4747+ * intended for end users.
4848+ *
4949+ * If there are no errors, `*errorbuf' will be set to NULL. The
5050+ * buffer `*errorbuf' should be deallocated with `sandbox_free_error'.
5151+ *
5252+ * @result 0 on success, -1 otherwise.
5353+ */
5454+int sandbox_init(const char *profile, uint64_t flags, char **errorbuf);
5555+5656+/*
5757+ * @define SANDBOX_NAMED The `profile' argument specifies a Sandbox
5858+ * profile named by one of the kSBXProfile* string constants.
5959+ */
6060+#define SANDBOX_NAMED 0x0001
6161+6262+#ifdef __APPLE_API_PRIVATE
6363+6464+/* The following flags are reserved for Mac OS X. Developers should not
6565+ * depend on their availability.
6666+ */
6767+6868+/*
6969+ * @define SANDBOX_NAMED_BUILTIN The `profile' argument specifies the
7070+ * name of a builtin profile that is statically compiled into the
7171+ * system.
7272+ */
7373+#define SANDBOX_NAMED_BUILTIN 0x0002
7474+7575+/*
7676+ * @define SANDBOX_NAMED_EXTERNAL The `profile' argument specifies the
7777+ * pathname of a Sandbox profile. The pathname may be abbreviated: If
7878+ * the name does not start with a `/' it is treated as relative to
7979+ * /usr/share/sandbox and a `.sb' suffix is appended.
8080+ */
8181+#define SANDBOX_NAMED_EXTERNAL 0x0003
8282+8383+/*
8484+ * @define SANDBOX_NAMED_MASK Mask for name types: 4 bits, 15 possible
8585+ * name types, 3 currently defined.
8686+ */
8787+#define SANDBOX_NAMED_MASK 0x000f
8888+8989+#endif /* __APPLE_API_PRIVATE */
9090+9191+/*
9292+ * Available Sandbox profiles.
9393+ */
9494+9595+/* TCP/IP networking is prohibited. */
9696+extern const char kSBXProfileNoInternet[];
9797+9898+/* All sockets-based networking is prohibited. */
9999+extern const char kSBXProfileNoNetwork[];
100100+101101+/* File system writes are prohibited. */
102102+extern const char kSBXProfileNoWrite[];
103103+104104+/* File system writes are restricted to temporary folders /var/tmp and
105105+ * confstr(_CS_DARWIN_USER_DIR, ...).
106106+ */
107107+extern const char kSBXProfileNoWriteExceptTemporary[];
108108+109109+/* All operating system services are prohibited. */
110110+extern const char kSBXProfilePureComputation[];
111111+112112+/*
113113+ * @function sandbox_free_error
114114+ * Deallocates an error string previously allocated by sandbox_init.
115115+ *
116116+ * @param errorbuf (input) The buffer to be freed. Must be a pointer
117117+ * previously returned by sandbox_init in the `errorbuf' argument, or NULL.
118118+ *
119119+ * @result void
120120+ */
121121+void sandbox_free_error(char *errorbuf);
122122+123123+124124+#ifdef __APPLE_API_PRIVATE
125125+126126+/* The following definitions are reserved for Mac OS X. Developers should not
127127+ * depend on their availability.
128128+ */
129129+130130+int sandbox_init_with_parameters(const char *profile, uint64_t flags, const char *const parameters[], char **errorbuf);
131131+132132+int sandbox_init_with_extensions(const char *profile, uint64_t flags, const char *const extensions[], char **errorbuf);
133133+134134+enum sandbox_filter_type {
135135+ SANDBOX_FILTER_NONE,
136136+ SANDBOX_FILTER_PATH,
137137+ SANDBOX_FILTER_GLOBAL_NAME,
138138+ SANDBOX_FILTER_LOCAL_NAME,
139139+ SANDBOX_FILTER_APPLEEVENT_DESTINATION,
140140+ SANDBOX_FILTER_RIGHT_NAME,
141141+};
142142+143143+extern const enum sandbox_filter_type SANDBOX_CHECK_NO_REPORT __attribute__((weak_import));
144144+145145+enum sandbox_extension_flags {
146146+ FS_EXT_DEFAULTS = 0,
147147+ FS_EXT_FOR_PATH = (1 << 0),
148148+ FS_EXT_FOR_FILE = (1 << 1),
149149+ FS_EXT_READ = (1 << 2),
150150+ FS_EXT_WRITE = (1 << 3),
151151+ FS_EXT_PREFER_FILEID = (1 << 4),
152152+};
153153+154154+int sandbox_check(pid_t pid, const char *operation, enum sandbox_filter_type type, ...);
155155+156156+int sandbox_note(const char *note);
157157+158158+int sandbox_suspend(pid_t pid);
159159+int sandbox_unsuspend(void);
160160+161161+int sandbox_issue_extension(const char *path, char **ext_token);
162162+int sandbox_issue_fs_extension(const char *path, uint64_t flags, char **ext_token);
163163+int sandbox_issue_fs_rw_extension(const char *path, char **ext_token);
164164+int sandbox_issue_mach_extension(const char *name, char **ext_token);
165165+166166+int sandbox_consume_extension(const char *path, const char *ext_token);
167167+int sandbox_consume_fs_extension(const char *ext_token, char **path);
168168+int sandbox_consume_mach_extension(const char *ext_token, char **name);
169169+170170+int sandbox_release_fs_extension(const char *ext_token);
171171+172172+int sandbox_container_path_for_pid(pid_t pid, char *buffer, size_t bufsize);
173173+174174+int sandbox_wakeup_daemon(char **errorbuf);
175175+176176+const char *_amkrtemp(const char *);
177177+178178+#endif /* __APPLE_API_PRIVATE */
179179+180180+__END_DECLS
181181+#endif /* _SANDBOX_H_ */