From owner-svn-src-head@freebsd.org Wed Jun 5 22:40:51 2019 Return-Path: Delivered-To: svn-src-head@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 DD6F915BB552; Wed, 5 Jun 2019 22:40:50 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 814D27004F; Wed, 5 Jun 2019 22:40:50 +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 5BB73B811; Wed, 5 Jun 2019 22:40:50 +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 x55Meoti013554; Wed, 5 Jun 2019 22:40:50 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x55MeosV013552; Wed, 5 Jun 2019 22:40:50 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201906052240.x55MeosV013552@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Wed, 5 Jun 2019 22:40:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r348708 - head/usr.bin/tail X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: head/usr.bin/tail X-SVN-Commit-Revision: 348708 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 814D27004F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.964,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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: Wed, 05 Jun 2019 22:40:51 -0000 Author: oshogbo Date: Wed Jun 5 22:40:49 2019 New Revision: 348708 URL: https://svnweb.freebsd.org/changeset/base/348708 Log: tail: capsicumize Submitted by: Nik Sultana Differential Revision: https://reviews.freebsd.org/D20393 Modified: head/usr.bin/tail/Makefile head/usr.bin/tail/tail.c Modified: head/usr.bin/tail/Makefile ============================================================================== --- head/usr.bin/tail/Makefile Wed Jun 5 22:36:19 2019 (r348707) +++ head/usr.bin/tail/Makefile Wed Jun 5 22:40:49 2019 (r348708) @@ -6,6 +6,12 @@ PROG= tail SRCS= forward.c misc.c read.c reverse.c tail.c +.if ${MK_CASPER} != "no" +LIBADD+= casper +LIBADD+= cap_fileargs +CFLAGS+= -DWITH_CASPER +.endif + HAS_TESTS= SUBDIR.${MK_TESTS}+= tests Modified: head/usr.bin/tail/tail.c ============================================================================== --- head/usr.bin/tail/tail.c Wed Jun 5 22:36:19 2019 (r348707) +++ head/usr.bin/tail/tail.c Wed Jun 5 22:40:49 2019 (r348708) @@ -46,9 +46,11 @@ static const char copyright[] = static const char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93"; #endif +#include #include #include +#include #include #include #include @@ -57,6 +59,9 @@ static const char sccsid[] = "@(#)tail.c 8.1 (Berkeley #include #include +#include +#include + #include "extern.h" int Fflag, fflag, qflag, rflag, rval, no_files; @@ -85,7 +90,14 @@ main(int argc, char *argv[]) int i, ch, first; file_info_t *file; char *p; + fileargs_t *fa; + cap_rights_t rights; + cap_rights_init(&rights, CAP_FSTAT, CAP_FCNTL, CAP_MMAP_RW); + if (caph_rights_limit(STDIN_FILENO, &rights) < 0 || + caph_limit_stderr() < 0 || caph_limit_stdout() < 0) + err(1, "can't limit stdio rights"); + /* * Tail's options are weird. First, -n10 is the same as -n-10, not * -n+10. Second, the number options are 1 based and not offsets, @@ -155,6 +167,15 @@ main(int argc, char *argv[]) no_files = argc ? argc : 1; + fa = fileargs_init(argc, argv, O_RDONLY, 0, &rights, FA_OPEN); + if (fa == NULL) + errx(1, "unable to init casper"); + + caph_cache_catpages(); + if (caph_enter_casper() < 0) + err(1, "unable to enter capability mode"); + + /* * If displaying in reverse, don't permit follow option, and convert * style values. @@ -192,7 +213,7 @@ main(int argc, char *argv[]) file->file_name = strdup(fn); if (! file->file_name) errx(1, "Couldn't malloc space for file name."); - if ((file->fp = fopen(file->file_name, "r")) == NULL || + if ((file->fp = fileargs_fopen(fa, file->file_name, "r")) == NULL || fstat(fileno(file->fp), &file->st)) { if (file->fp != NULL) { fclose(file->fp); @@ -209,7 +230,7 @@ main(int argc, char *argv[]) free(files); } else if (*argv) { for (first = 1; (fn = *argv++);) { - if ((fp = fopen(fn, "r")) == NULL || + if ((fp = fileargs_fopen(fa, fn, "r")) == NULL || fstat(fileno(fp), &sb)) { ierr(fn); continue; @@ -247,6 +268,7 @@ main(int argc, char *argv[]) else forward(stdin, fn, style, off, &sb); } + fileargs_free(fa); exit(rval); }