xref: /netbsd-src/crypto/external/bsd/openssh/dist/sandbox-pledge.c (revision 17418e98f281f84e3d22de9717222f9c2ee84d3a)
1 /*	$NetBSD: sandbox-pledge.c,v 1.3 2021/03/05 17:47:16 christos Exp $	*/
2 /* $OpenBSD: sandbox-pledge.c,v 1.2 2020/10/18 11:32:01 djm Exp $ */
3 
4 /*
5  * Copyright (c) 2015 Theo de Raadt <deraadt@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 #include "includes.h"
20 __RCSID("$NetBSD: sandbox-pledge.c,v 1.3 2021/03/05 17:47:16 christos Exp $");
21 
22 #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 
40 struct ssh_sandbox {
41 	pid_t child_pid;
42 };
43 
44 struct ssh_sandbox *
ssh_sandbox_init(void)45 ssh_sandbox_init(void)
46 {
47 	struct ssh_sandbox *box;
48 
49 	debug3_f("preparing pledge sandbox");
50 	box = xcalloc(1, sizeof(*box));
51 	box->child_pid = 0;
52 
53 	return box;
54 }
55 
56 void
ssh_sandbox_child(struct ssh_sandbox * box)57 ssh_sandbox_child(struct ssh_sandbox *box)
58 {
59 	if (pledge("stdio", NULL) == -1)
60 		fatal_f("pledge()");
61 }
62 
63 void
ssh_sandbox_parent_finish(struct ssh_sandbox * box)64 ssh_sandbox_parent_finish(struct ssh_sandbox *box)
65 {
66 	free(box);
67 	debug3_f("finished");
68 }
69 
70 void
ssh_sandbox_parent_preauth(struct ssh_sandbox * box,pid_t child_pid)71 ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
72 {
73 	box->child_pid = child_pid;
74 	/* Nothing to do here */
75 }
76