summaryrefslogtreecommitdiff
path: root/sandbox-solaris.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2016-01-08 14:24:56 +1100
committerDamien Miller <djm@mindrot.org>2016-01-08 14:29:12 +1100
commit4626cbaf78767fc8e9c86dd04785386c59ae0839 (patch)
tree449a777d8781a7f88724cbec9a4717f5b3fe4ec6 /sandbox-solaris.c
parent422d1b3ee977ff4c724b597fb2e437d38fc8de9d (diff)
Support Illumos/Solaris fine-grained privileges
Includes a pre-auth privsep sandbox and several pledge() emulations. bz#2511, patch by Alex Wilson. ok dtucker@
Diffstat (limited to 'sandbox-solaris.c')
-rw-r--r--sandbox-solaris.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/sandbox-solaris.c b/sandbox-solaris.c
new file mode 100644
index 000000000..98714e170
--- /dev/null
+++ b/sandbox-solaris.c
@@ -0,0 +1,107 @@
1/*
2 * Copyright (c) 2015 Joyent, Inc
3 * Author: Alex Wilson <alex.wilson@joyent.com>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "includes.h"
19
20#ifdef SANDBOX_SOLARIS
21#ifndef USE_SOLARIS_PRIVS
22# error "--with-solaris-privs must be used with the Solaris sandbox"
23#endif
24
25#include <sys/types.h>
26
27#include <errno.h>
28#include <stdarg.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <unistd.h>
33#ifdef HAVE_PRIV_H
34# include <priv.h>
35#endif
36
37#include "log.h"
38#include "ssh-sandbox.h"
39#include "xmalloc.h"
40
41struct ssh_sandbox {
42 priv_set_t *pset;
43};
44
45struct ssh_sandbox *
46ssh_sandbox_init(struct monitor *monitor)
47{
48 struct ssh_sandbox *box = NULL;
49
50 box = xcalloc(1, sizeof(*box));
51 box->pset = priv_allocset();
52
53 if (box->pset == NULL) {
54 free(box);
55 return NULL;
56 }
57
58 /* Start with "basic" and drop everything we don't need. */
59 priv_basicset(box->pset);
60
61 /* Drop everything except the ability to use already-opened files */
62 if (priv_delset(box->pset, PRIV_FILE_LINK_ANY) != 0 ||
63 priv_delset(box->pset, PRIV_NET_ACCESS) != 0 ||
64 priv_delset(box->pset, PRIV_PROC_EXEC) != 0 ||
65 priv_delset(box->pset, PRIV_PROC_FORK) != 0 ||
66 priv_delset(box->pset, PRIV_PROC_INFO) != 0 ||
67 priv_delset(box->pset, PRIV_PROC_SESSION) != 0) {
68 free(box);
69 return NULL;
70 }
71
72 /* These may not be available on older Solaris-es */
73# if defined(PRIV_FILE_READ) && defined(PRIV_FILE_WRITE)
74 if (priv_delset(box->pset, PRIV_FILE_READ) != 0 ||
75 priv_delset(box->pset, PRIV_FILE_WRITE) != 0) {
76 free(box);
77 return NULL;
78 }
79# endif
80
81 return box;
82}
83
84void
85ssh_sandbox_child(struct ssh_sandbox *box)
86{
87 if (setppriv(PRIV_SET, PRIV_PERMITTED, box->pset) != 0 ||
88 setppriv(PRIV_SET, PRIV_LIMIT, box->pset) != 0 ||
89 setppriv(PRIV_SET, PRIV_INHERITABLE, box->pset) != 0)
90 fatal("setppriv: %s", strerror(errno));
91}
92
93void
94ssh_sandbox_parent_finish(struct ssh_sandbox *box)
95{
96 priv_freeset(box->pset);
97 box->pset = NULL;
98 free(box);
99}
100
101void
102ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
103{
104 /* Nothing to do here */
105}
106
107#endif /* SANDBOX_SOLARIS */