From owner-svn-src-head@freebsd.org Mon Sep 19 16:16:15 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 34B11BE147F; Mon, 19 Sep 2016 16:16:15 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 078601180; Mon, 19 Sep 2016 16:16:14 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8JGGEnI037047; Mon, 19 Sep 2016 16:16:14 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8JGGEuH037046; Mon, 19 Sep 2016 16:16:14 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201609191616.u8JGGEuH037046@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Mon, 19 Sep 2016 16:16:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305983 - head/usr.bin/indent X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Sep 2016 16:16:15 -0000 Author: cem Date: Mon Sep 19 16:16:14 2016 New Revision: 305983 URL: https://svnweb.freebsd.org/changeset/base/305983 Log: indent(1): Capsicumify This is a nice and trivial program for sandboxing. One input file, one output file. Reviewed by: pfg Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D7920 Modified: head/usr.bin/indent/indent.c Modified: head/usr.bin/indent/indent.c ============================================================================== --- head/usr.bin/indent/indent.c Mon Sep 19 16:14:38 2016 (r305982) +++ head/usr.bin/indent/indent.c Mon Sep 19 16:16:14 2016 (r305983) @@ -50,8 +50,10 @@ static char sccsid[] = "@(#)indent.c 5.1 #include __FBSDID("$FreeBSD$"); +#include #include #include +#include #include #include #include @@ -74,6 +76,7 @@ char bakfile[MAXPATHLEN] = ""; int main(int argc, char **argv) { + cap_rights_t rights; int dec_ind; /* current indentation for declarations */ int di_stack[20]; /* a stack of structure indentation levels */ @@ -234,6 +237,17 @@ main(int argc, char **argv) bakcopy(); } } + + /* Restrict input/output descriptors and enter Capsicum sandbox. */ + cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE); + if (cap_rights_limit(fileno(output), &rights) < 0 && errno != ENOSYS) + err(EXIT_FAILURE, "unable to limit rights for %s", out_name); + cap_rights_init(&rights, CAP_FSTAT, CAP_READ); + if (cap_rights_limit(fileno(input), &rights) < 0 && errno != ENOSYS) + err(EXIT_FAILURE, "unable to limit rights for %s", in_name); + if (cap_enter() < 0 && errno != ENOSYS) + err(EXIT_FAILURE, "unable to enter capability mode"); + if (ps.com_ind <= 1) ps.com_ind = 2; /* dont put normal comments before column 2 */ if (troff) {