From owner-svn-src-all@freebsd.org Mon Nov 12 17:59:17 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 07619110CF00; Mon, 12 Nov 2018 17:59:17 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7FFC57AFD9; Mon, 12 Nov 2018 17:59:16 +0000 (UTC) (envelope-from oshogbo@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5ACF8241A9; Mon, 12 Nov 2018 17:59:16 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wACHxGkK065661; Mon, 12 Nov 2018 17:59:16 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wACHxFEn065659; Mon, 12 Nov 2018 17:59:15 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201811121759.wACHxFEn065659@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Mon, 12 Nov 2018 17:59:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r340376 - head/usr.bin/head X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: head/usr.bin/head X-SVN-Commit-Revision: 340376 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 7FFC57AFD9 X-Spamd-Result: default: False [-102.59 / 200.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; ALLOW_DOMAIN_WHITELIST(-100.00)[FreeBSD.org]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; HAS_XAW(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; DMARC_NA(0.00)[FreeBSD.org]; RCVD_COUNT_THREE(0.00)[4]; MX_GOOD(-0.01)[cached: mx1.FreeBSD.org]; NEURAL_HAM_SHORT(-0.48)[-0.476,0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Nov 2018 17:59:17 -0000 Author: oshogbo Date: Mon Nov 12 17:59:15 2018 New Revision: 340376 URL: https://svnweb.freebsd.org/changeset/base/340376 Log: head: sandbox using capsicum Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D14409 Modified: head/usr.bin/head/Makefile head/usr.bin/head/head.c Modified: head/usr.bin/head/Makefile ============================================================================== --- head/usr.bin/head/Makefile Mon Nov 12 17:57:12 2018 (r340375) +++ head/usr.bin/head/Makefile Mon Nov 12 17:59:15 2018 (r340376) @@ -8,4 +8,10 @@ PROG= head HAS_TESTS= SUBDIR.${MK_TESTS}+= tests +.if ${MK_CASPER} != "no" && !defined(RESCUE) +LIBADD+= casper +LIBADD+= cap_fileargs +CFLAGS+=-DWITH_CASPER +.endif + .include Modified: head/usr.bin/head/head.c ============================================================================== --- head/usr.bin/head/head.c Mon Nov 12 17:57:12 2018 (r340375) +++ head/usr.bin/head/head.c Mon Nov 12 17:59:15 2018 (r340376) @@ -43,10 +43,13 @@ static char sccsid[] = "@(#)head.c 8.2 (Berkeley) 5/4/ #include __FBSDID("$FreeBSD$"); +#include #include +#include #include #include +#include #include #include #include @@ -54,6 +57,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include + /* * head - give the first few lines of a stream or of each of a set of files * @@ -79,6 +85,8 @@ main(int argc, char *argv[]) char *ep; off_t bytecnt; int ch, first, linecnt, eval; + fileargs_t *fa; + cap_rights_t rights; linecnt = -1; eval = 0; @@ -106,13 +114,22 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + fa = fileargs_init(argc, argv, O_RDONLY, 0, + cap_rights_init(&rights, CAP_READ, CAP_FSTAT, CAP_FCNTL)); + if (fa == NULL) + errx(1, "unable to init casper"); + + caph_cache_catpages(); + if (caph_limit_stdio() < 0 || caph_enter_casper() < 0) + err(1, "unable to enter capability mode"); + if (linecnt != -1 && bytecnt != -1) errx(1, "can't combine line and byte counts"); if (linecnt == -1) linecnt = 10; if (*argv != NULL) { for (first = 1; *argv != NULL; ++argv) { - if ((fp = fopen(*argv, "r")) == NULL) { + if ((fp = fileargs_fopen(fa, *argv, "r")) == NULL) { warn("%s", *argv); eval = 1; continue; @@ -133,6 +150,7 @@ main(int argc, char *argv[]) else head_bytes(stdin, bytecnt); + fileargs_free(fa); exit(eval); }