155714Skris/*
255714Skris * Copyright (c) 2015 Joyent, Inc
355714Skris * Author: Alex Wilson <alex.wilson@joyent.com>
455714Skris *
555714Skris * Permission to use, copy, modify, and distribute this software for any
655714Skris * purpose with or without fee is hereby granted, provided that the above
755714Skris * copyright notice and this permission notice appear in all copies.
8296465Sdelphij *
955714Skris * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1055714Skris * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1155714Skris * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1255714Skris * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1355714Skris * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1455714Skris * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15296465Sdelphij * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1655714Skris */
1755714Skris
1855714Skris#include "includes.h"
1955714Skris
2055714Skris#ifdef SANDBOX_SOLARIS
2155714Skris#ifndef USE_SOLARIS_PRIVS
22296465Sdelphij# error "--with-solaris-privs must be used with the Solaris sandbox"
2355714Skris#endif
2455714Skris
2555714Skris#include <sys/types.h>
2655714Skris
2755714Skris#include <errno.h>
2855714Skris#include <stdarg.h>
2955714Skris#include <stdio.h>
3055714Skris#include <stdlib.h>
3155714Skris#include <string.h>
3255714Skris#include <unistd.h>
3355714Skris#ifdef HAVE_PRIV_H
3455714Skris# include <priv.h>
3555714Skris#endif
3655714Skris
37296465Sdelphij#include "log.h"
3855714Skris#include "ssh-sandbox.h"
3955714Skris#include "xmalloc.h"
40296465Sdelphij
4155714Skrisstruct ssh_sandbox {
4255714Skris	priv_set_t *pset;
4355714Skris};
4455714Skris
4555714Skrisstruct ssh_sandbox *
4655714Skrisssh_sandbox_init(struct monitor *monitor)
4755714Skris{
4855714Skris	struct ssh_sandbox *box = NULL;
4955714Skris
5055714Skris	box = xcalloc(1, sizeof(*box));
5155714Skris
52296465Sdelphij	/* Start with "basic" and drop everything we don't need. */
5355714Skris	box->pset = solaris_basic_privset();
5455714Skris
5555714Skris	if (box->pset == NULL) {
5655714Skris		free(box);
5755714Skris		return NULL;
5855714Skris	}
5955714Skris
60160814Ssimon	/* Drop everything except the ability to use already-opened files */
6155714Skris	if (priv_delset(box->pset, PRIV_FILE_LINK_ANY) != 0 ||
6255714Skris#ifdef PRIV_NET_ACCESS
6355714Skris	    priv_delset(box->pset, PRIV_NET_ACCESS) != 0 ||
6455714Skris#endif
6555714Skris	    priv_delset(box->pset, PRIV_PROC_EXEC) != 0 ||
66296465Sdelphij	    priv_delset(box->pset, PRIV_PROC_FORK) != 0 ||
67296465Sdelphij	    priv_delset(box->pset, PRIV_PROC_INFO) != 0 ||
68296465Sdelphij	    priv_delset(box->pset, PRIV_PROC_SESSION) != 0) {
69296465Sdelphij		free(box);
70296465Sdelphij		return NULL;
71296465Sdelphij	}
72296465Sdelphij
73296465Sdelphij	/* These may not be available on older Solaris-es */
74296465Sdelphij# if defined(PRIV_FILE_READ) && defined(PRIV_FILE_WRITE)
7555714Skris	if (priv_delset(box->pset, PRIV_FILE_READ) != 0 ||
76296465Sdelphij	    priv_delset(box->pset, PRIV_FILE_WRITE) != 0) {
77296465Sdelphij		free(box);
78296465Sdelphij		return NULL;
79296465Sdelphij	}
80296465Sdelphij# endif
81296465Sdelphij
82296465Sdelphij	return box;
83296465Sdelphij}
84296465Sdelphij
85109998Smarkmvoid
86109998Smarkmssh_sandbox_child(struct ssh_sandbox *box)
87109998Smarkm{
88296465Sdelphij	if (setppriv(PRIV_SET, PRIV_PERMITTED, box->pset) != 0 ||
89296465Sdelphij	    setppriv(PRIV_SET, PRIV_LIMIT, box->pset) != 0 ||
90215697Ssimon	    setppriv(PRIV_SET, PRIV_INHERITABLE, box->pset) != 0)
91296465Sdelphij		fatal("setppriv: %s", strerror(errno));
92296465Sdelphij}
93215697Ssimon
94296465Sdelphijvoid
95296465Sdelphijssh_sandbox_parent_finish(struct ssh_sandbox *box)
96296465Sdelphij{
97109998Smarkm	priv_freeset(box->pset);
98296465Sdelphij	box->pset = NULL;
99296465Sdelphij	free(box);
100296465Sdelphij}
10155714Skris
10255714Skrisvoid
103194206Ssimonssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
104296465Sdelphij{
105296465Sdelphij	/* Nothing to do here */
106296465Sdelphij}
107296465Sdelphij
108194206Ssimon#endif /* SANDBOX_SOLARIS */
109296465Sdelphij