Page MenuHomeFreeBSD

D14409.id43156.diff
No OneTemporary

D14409.id43156.diff

Index: usr.bin/head/Makefile
===================================================================
--- usr.bin/head/Makefile
+++ usr.bin/head/Makefile
@@ -8,4 +8,10 @@
HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
+.if ${MK_CASPER} != "no" && !defined(RESCUE)
+LIBADD+= casper
+LIBADD+= cap_fileargs
+CFLAGS+=-DWITH_CASPER
+.endif
+
.include <bsd.prog.mk>
Index: usr.bin/head/head.c
===================================================================
--- usr.bin/head/head.c
+++ usr.bin/head/head.c
@@ -44,9 +44,12 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
+#include <sys/capsicum.h>
+#include <capsicum_helpers.h>
#include <ctype.h>
#include <err.h>
+#include <errno.h>
#include <getopt.h>
#include <inttypes.h>
#include <stdio.h>
@@ -54,6 +57,9 @@
#include <string.h>
#include <unistd.h>
+#include <libcasper.h>
+#include <casper/cap_fileargs.h>
+
/*
* head - give the first few lines of a stream or of each of a set of files
*
@@ -80,6 +86,8 @@
int first, linecnt = -1, eval = 0;
off_t bytecnt = -1;
char *ep;
+ fileargs_t *fa;
+ cap_rights_t rights;
obsolete(argv);
while ((ch = getopt_long(argc, argv, "+n:c:", long_opts, NULL)) != -1)
@@ -101,13 +109,22 @@
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) {
for (first = 1; *argv; ++argv) {
- if ((fp = fopen(*argv, "r")) == NULL) {
+ if ((fp = fileargs_fopen(fa, *argv, "r")) == NULL) {
warn("%s", *argv);
eval = 1;
continue;
@@ -128,6 +145,7 @@
else
head_bytes(stdin, bytecnt);
+ fileargs_free(fa);
exit(eval);
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 21, 5:05 PM (3 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25780061
Default Alt Text
D14409.id43156.diff (1 KB)

Event Timeline