From owner-svn-src-all@freebsd.org Sun Nov 18 12:23:04 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 C13821138501; Sun, 18 Nov 2018 12:23:04 +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 6311C7AE83; Sun, 18 Nov 2018 12:23:04 +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 3F23413503; Sun, 18 Nov 2018 12:23:04 +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 wAICN47c058519; Sun, 18 Nov 2018 12:23:04 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wAICN3co058518; Sun, 18 Nov 2018 12:23:03 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201811181223.wAICN3co058518@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Sun, 18 Nov 2018 12:23:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r340572 - head/usr.bin/brandelf X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: head/usr.bin/brandelf X-SVN-Commit-Revision: 340572 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6311C7AE83 X-Spamd-Result: default: False [0.03 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_SPAM_SHORT(0.03)[0.033,0] 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: Sun, 18 Nov 2018 12:23:05 -0000 Author: oshogbo Date: Sun Nov 18 12:23:03 2018 New Revision: 340572 URL: https://svnweb.freebsd.org/changeset/base/340572 Log: brandelf: capsicumize it Modified: head/usr.bin/brandelf/Makefile head/usr.bin/brandelf/brandelf.c Modified: head/usr.bin/brandelf/Makefile ============================================================================== --- head/usr.bin/brandelf/Makefile Sun Nov 18 12:09:27 2018 (r340571) +++ head/usr.bin/brandelf/Makefile Sun Nov 18 12:23:03 2018 (r340572) @@ -1,5 +1,13 @@ # $FreeBSD$ +.include + PROG= brandelf + +.if ${MK_CASPER} != "no" +LIBADD+= casper +LIBADD+= cap_fileargs +CFLAGS+= -DWITH_CASPER +.endif .include Modified: head/usr.bin/brandelf/brandelf.c ============================================================================== --- head/usr.bin/brandelf/brandelf.c Sun Nov 18 12:09:27 2018 (r340571) +++ head/usr.bin/brandelf/brandelf.c Sun Nov 18 12:23:03 2018 (r340572) @@ -33,9 +33,11 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include +#include #include #include #include @@ -44,6 +46,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include + static int elftype(const char *); static const char *iselftype(int); static void printelftypes(void); @@ -66,8 +71,10 @@ main(int argc, char **argv) { const char *strtype = "FreeBSD"; - int ch, retval, type; + int ch, flags, retval, type; bool change, force, listed; + fileargs_t *fa; + cap_rights_t rights; type = ELFOSABI_FREEBSD; retval = 0; @@ -121,11 +128,24 @@ main(int argc, char **argv) usage(); } + flags = change || force ? O_RDWR : O_RDONLY; + cap_rights_init(&rights, CAP_READ, CAP_SEEK); + if (flags == O_RDWR) + cap_rights_set(&rights, CAP_WRITE); + + fa = fileargs_init(argc, argv, flags, 0, &rights); + 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"); + while (argc != 0) { int fd; char buffer[EI_NIDENT]; - if ((fd = open(argv[0], change || force ? O_RDWR : O_RDONLY, 0)) < 0) { + if ((fd = fileargs_open(fa, argv[0])) < 0) { warn("error opening file %s", argv[0]); retval = 1; goto fail; @@ -167,6 +187,7 @@ fail: argv++; } + fileargs_free(fa); return (retval); }