From owner-svn-src-all@freebsd.org Tue Nov 8 05:31:04 2016 Return-Path: Delivered-To: svn-src-all@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 3B259C34591; Tue, 8 Nov 2016 05:31:04 +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 15748C3E; Tue, 8 Nov 2016 05:31:04 +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 uA85V3g1025396; Tue, 8 Nov 2016 05:31:03 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA85V2DL025382; Tue, 8 Nov 2016 05:31:02 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201611080531.uA85V2DL025382@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Tue, 8 Nov 2016 05:31:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r308432 - in head: bin/echo bin/sleep usr.bin/basename usr.bin/dc usr.bin/dirname usr.bin/fold usr.bin/getopt usr.bin/locate/bigram usr.bin/logname usr.bin/printenv usr.bin/yes X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 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: Tue, 08 Nov 2016 05:31:04 -0000 Author: cem Date: Tue Nov 8 05:31:01 2016 New Revision: 308432 URL: https://svnweb.freebsd.org/changeset/base/308432 Log: Capsicumize some trivial stdio programs Trivially capsicumize some simple programs that just interact with stdio. This list of programs uses 'pledge("stdio")' in OpenBSD. No objection from: allanjude, emaste, oshogbo Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D8307 Modified: head/bin/echo/echo.c head/bin/sleep/sleep.c head/usr.bin/basename/basename.c head/usr.bin/dc/dc.c head/usr.bin/dirname/dirname.c head/usr.bin/fold/fold.c head/usr.bin/getopt/getopt.c head/usr.bin/locate/bigram/locate.bigram.c head/usr.bin/logname/logname.c head/usr.bin/printenv/printenv.c head/usr.bin/yes/yes.c Modified: head/bin/echo/echo.c ============================================================================== --- head/bin/echo/echo.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/bin/echo/echo.c Tue Nov 8 05:31:01 2016 (r308432) @@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include #include #include #include @@ -78,6 +80,9 @@ main(int argc, char *argv[]) char newline[] = "\n"; char *progname = argv[0]; + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + /* This utility may NOT do getopt(3) option parsing. */ if (*++argv && !strcmp(*argv, "-n")) { ++argv; Modified: head/bin/sleep/sleep.c ============================================================================== --- head/bin/sleep/sleep.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/bin/sleep/sleep.c Tue Nov 8 05:31:01 2016 (r308432) @@ -41,6 +41,7 @@ static char sccsid[] = "@(#)sleep.c 8.3 #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -69,6 +70,9 @@ main(int argc, char *argv[]) time_t original; char buf[2]; + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + if (argc != 2) usage(); Modified: head/usr.bin/basename/basename.c ============================================================================== --- head/usr.bin/basename/basename.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/basename/basename.c Tue Nov 8 05:31:01 2016 (r308432) @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)basename.c 8 #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -64,6 +65,9 @@ main(int argc, char **argv) setlocale(LC_ALL, ""); + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + aflag = 0; suffix = NULL; suffixlen = 0; Modified: head/usr.bin/dc/dc.c ============================================================================== --- head/usr.bin/dc/dc.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/dc/dc.c Tue Nov 8 05:31:01 2016 (r308432) @@ -22,9 +22,11 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include +#include #include #include #include @@ -58,11 +60,11 @@ usage(void) } static void -procfile(char *fname) { +procfd(int fd, char *fname) { struct stat st; FILE *file; - file = fopen(fname, "r"); + file = fdopen(fd, "r"); if (file == NULL) err(1, "cannot open file %s", fname); if (fstat(fileno(file), &st) == -1) @@ -80,7 +82,7 @@ procfile(char *fname) { int main(int argc, char *argv[]) { - int ch; + int ch, fd; bool extended_regs = false, preproc_done = false; /* accept and ignore a single dash to be 4.4BSD dc(1) compatible */ @@ -97,7 +99,10 @@ main(int argc, char *argv[]) case 'f': if (!preproc_done) init_bmachine(extended_regs); - procfile(optarg); + fd = open(optarg, O_RDONLY); + if (fd < 0) + err(1, "cannot open file %s", optarg); + procfd(fd, optarg); preproc_done = true; break; case 'x': @@ -126,12 +131,23 @@ main(int argc, char *argv[]) if (argc > 1) usage(); if (argc == 1) { - procfile(argv[0]); + fd = open(argv[0], O_RDONLY); + if (fd < 0) + err(1, "cannot open file %s", argv[0]); + + if (caph_limit_stream(fd, CAPH_READ) < 0 || + caph_limit_stdio() < 0 || + (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + + procfd(fd, argv[0]); preproc_done = true; } if (preproc_done) return (0); + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); src_setstream(&src, stdin); reset_bmachine(&src); eval(); Modified: head/usr.bin/dirname/dirname.c ============================================================================== --- head/usr.bin/dirname/dirname.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/dirname/dirname.c Tue Nov 8 05:31:01 2016 (r308432) @@ -39,6 +39,7 @@ static const char sccsid[] = "@(#)dirnam #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -53,6 +54,9 @@ main(int argc, char **argv) char *p; int ch; + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': Modified: head/usr.bin/fold/fold.c ============================================================================== --- head/usr.bin/fold/fold.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/fold/fold.c Tue Nov 8 05:31:01 2016 (r308432) @@ -45,6 +45,7 @@ static char sccsid[] = "@(#)fold.c 8.1 ( #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -72,6 +73,9 @@ main(int argc, char **argv) (void) setlocale(LC_CTYPE, ""); + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + width = -1; previous_ch = 0; while ((ch = getopt(argc, argv, "0123456789bsw:")) != -1) { Modified: head/usr.bin/getopt/getopt.c ============================================================================== --- head/usr.bin/getopt/getopt.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/getopt/getopt.c Tue Nov 8 05:31:01 2016 (r308432) @@ -6,6 +6,9 @@ __FBSDID("$FreeBSD$"); * into the public domain and is thus not subject to any copyright. */ +#include +#include +#include #include #include #include @@ -16,6 +19,9 @@ main(int argc, char *argv[]) int c; int status = 0; + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + optind = 2; /* Past the program name and the option letters. */ while ((c = getopt(argc, argv, argv[1])) != -1) switch (c) { Modified: head/usr.bin/locate/bigram/locate.bigram.c ============================================================================== --- head/usr.bin/locate/bigram/locate.bigram.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/locate/bigram/locate.bigram.c Tue Nov 8 05:31:01 2016 (r308432) @@ -57,6 +57,9 @@ static char sccsid[] = "@(#)locate.bigra * Use 'code' to encode a file using this output. */ +#include +#include +#include #include #include #include /* for MAXPATHLEN */ @@ -73,6 +76,9 @@ main(void) u_char *oldpath = buf1, *path = buf2; u_int i, j; + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + while (fgets(path, sizeof(buf2), stdin) != NULL) { /* Modified: head/usr.bin/logname/logname.c ============================================================================== --- head/usr.bin/logname/logname.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/logname/logname.c Tue Nov 8 05:31:01 2016 (r308432) @@ -39,6 +39,7 @@ static const char sccsid[] = "@(#)lognam #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -51,6 +52,9 @@ main(int argc, char *argv[] __unused) { char *p; + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + if (argc != 1) usage(); if ((p = getlogin()) == NULL) Modified: head/usr.bin/printenv/printenv.c ============================================================================== --- head/usr.bin/printenv/printenv.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/printenv/printenv.c Tue Nov 8 05:31:01 2016 (r308432) @@ -44,6 +44,8 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include #include #include @@ -65,6 +67,9 @@ main(int argc, char *argv[]) size_t len; int ch; + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': Modified: head/usr.bin/yes/yes.c ============================================================================== --- head/usr.bin/yes/yes.c Tue Nov 8 00:24:49 2016 (r308431) +++ head/usr.bin/yes/yes.c Tue Nov 8 05:31:01 2016 (r308432) @@ -41,12 +41,17 @@ static const char rcsid[] = "$FreeBSD$"; #endif #endif /* not lint */ +#include #include #include int main(int argc, char **argv) { + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); + if (argc > 1) while (puts(argv[1]) != EOF) ;