2 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
36 /* Darwin/OS X sandbox */
43 ssh_sandbox_init(void)
45 struct ssh_sandbox *box;
48 * Strictly, we don't need to maintain any state here but we need
49 * to return non-NULL to satisfy the API.
51 debug3("%s: preparing Darwin sandbox", __func__);
52 box = xcalloc(1, sizeof(*box));
59 ssh_sandbox_child(struct ssh_sandbox *box)
62 struct rlimit rl_zero;
64 debug3("%s: starting Darwin sandbox", __func__);
65 if (sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED,
67 fatal("%s: sandbox_init: %s", __func__, errmsg);
70 * The kSBXProfilePureComputation still allows sockets, so
71 * we must disable these using rlimit.
73 rl_zero.rlim_cur = rl_zero.rlim_max = 0;
74 if (setrlimit(RLIMIT_FSIZE, &rl_zero) == -1)
75 fatal("%s: setrlimit(RLIMIT_FSIZE, { 0, 0 }): %s",
76 __func__, strerror(errno));
77 if (setrlimit(RLIMIT_NOFILE, &rl_zero) == -1)
78 fatal("%s: setrlimit(RLIMIT_NOFILE, { 0, 0 }): %s",
79 __func__, strerror(errno));
80 if (setrlimit(RLIMIT_NPROC, &rl_zero) == -1)
81 fatal("%s: setrlimit(RLIMIT_NPROC, { 0, 0 }): %s",
82 __func__, strerror(errno));
86 ssh_sandbox_parent_finish(struct ssh_sandbox *box)
89 debug3("%s: finished", __func__);
93 ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
95 box->child_pid = child_pid;
98 #endif /* SANDBOX_DARWIN */