blob: d28fc27274e27b05b1dd14ccc76f0b8ea62d46fa [file] [log] [blame]
deraadt@openbsd.org2539dce2015-10-09 01:37:08 +00001/* $OpenBSD: sandbox-pledge.c,v 1.1 2015/10/09 01:37:08 deraadt Exp $ */
deraadt@openbsd.orgb19e1b42015-10-02 01:39:52 +00002/*
deraadt@openbsd.orgb0071592015-10-02 15:52:55 +00003 * Copyright (c) 2015 Theo de Raadt <deraadt@openbsd.org>
deraadt@openbsd.orgb19e1b42015-10-02 01:39:52 +00004 *
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
Damien Miller9846a2f2015-10-08 04:30:48 +110018#include "includes.h"
19
Damien Millerfafe1d82015-10-14 09:22:15 -070020#ifdef SANDBOX_PLEDGE
Damien Miller9846a2f2015-10-08 04:30:48 +110021
deraadt@openbsd.orgb19e1b42015-10-02 01:39:52 +000022#include <sys/types.h>
23#include <sys/ioctl.h>
24#include <sys/syscall.h>
25#include <sys/socket.h>
26#include <sys/wait.h>
27
28#include <errno.h>
29#include <limits.h>
30#include <stdarg.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <unistd.h>
34#include <pwd.h>
35
36#include "log.h"
37#include "ssh-sandbox.h"
38#include "xmalloc.h"
39
40struct ssh_sandbox {
41 pid_t child_pid;
42};
43
44struct ssh_sandbox *
Damien Miller9846a2f2015-10-08 04:30:48 +110045ssh_sandbox_init(struct monitor *m)
deraadt@openbsd.orgb19e1b42015-10-02 01:39:52 +000046{
47 struct ssh_sandbox *box;
48
deraadt@openbsd.org2539dce2015-10-09 01:37:08 +000049 debug3("%s: preparing pledge sandbox", __func__);
deraadt@openbsd.orgb19e1b42015-10-02 01:39:52 +000050 box = xcalloc(1, sizeof(*box));
51 box->child_pid = 0;
52
53 return box;
54}
55
56void
57ssh_sandbox_child(struct ssh_sandbox *box)
58{
deraadt@openbsd.org2539dce2015-10-09 01:37:08 +000059 if (pledge("stdio", NULL) == -1)
60 fatal("%s: pledge()", __func__);
deraadt@openbsd.orgb19e1b42015-10-02 01:39:52 +000061}
62
63void
64ssh_sandbox_parent_finish(struct ssh_sandbox *box)
65{
66 free(box);
67 debug3("%s: finished", __func__);
68}
69
70void
71ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
72{
73 box->child_pid = child_pid;
74 /* Nothing to do here */
75}
Damien Miller9846a2f2015-10-08 04:30:48 +110076
Damien Millerfafe1d82015-10-14 09:22:15 -070077#endif /* SANDBOX_PLEDGE */