1 /* $NetBSD: sandbox-pledge.c,v 1.2 2018/04/06 18:59:00 christos Exp $ */ 2 /* $OpenBSD: sandbox-pledge.c,v 1.1 2015/10/09 01:37:08 deraadt Exp $ */ 3 /* 4 * Copyright (c) 2015 Theo de Raadt <deraadt@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 #include "includes.h" 19 __RCSID("$NetBSD: sandbox-pledge.c,v 1.2 2018/04/06 18:59:00 christos Exp $"); 20 21 #include <sys/types.h> 22 #include <sys/ioctl.h> 23 #include <sys/syscall.h> 24 #include <sys/socket.h> 25 #include <sys/wait.h> 26 27 #include <errno.h> 28 #include <limits.h> 29 #include <stdarg.h> 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include <unistd.h> 33 #include <pwd.h> 34 35 #include "log.h" 36 #include "ssh-sandbox.h" 37 #include "xmalloc.h" 38 39 struct ssh_sandbox { 40 pid_t child_pid; 41 }; 42 43 struct ssh_sandbox * 44 ssh_sandbox_init(void) 45 { 46 struct ssh_sandbox *box; 47 48 debug3("%s: preparing pledge sandbox", __func__); 49 box = xcalloc(1, sizeof(*box)); 50 box->child_pid = 0; 51 52 return box; 53 } 54 55 void 56 ssh_sandbox_child(struct ssh_sandbox *box) 57 { 58 if (pledge("stdio", NULL) == -1) 59 fatal("%s: pledge()", __func__); 60 } 61 62 void 63 ssh_sandbox_parent_finish(struct ssh_sandbox *box) 64 { 65 free(box); 66 debug3("%s: finished", __func__); 67 } 68 69 void 70 ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid) 71 { 72 box->child_pid = child_pid; 73 /* Nothing to do here */ 74 } 75