paste(1): Capsicumise

Signed-off-by: Faraz Vahedi <kfv@kfv.io>
Reviewed by: imp, oshogbo
Pull Request: https://github.com/freebsd/freebsd-src/pull/1443
This commit is contained in:
Faraz Vahedi
2025-08-06 17:01:06 +03:30
committed by Warner Losh
parent 2e01fc43f2
commit 452ee04d62
2 changed files with 33 additions and 7 deletions
+8
View File
@@ -1,3 +1,11 @@
.include <src.opts.mk>
PROG= paste PROG= paste
.if ${MK_CASPER} != "no" && !defined(RESCUE)
LIBADD+= casper
LIBADD+= cap_fileargs
CFLAGS+= -DWITH_CASPER
.endif
.include <bsd.prog.mk> .include <bsd.prog.mk>
+25 -7
View File
@@ -34,9 +34,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/queue.h> #include <sys/queue.h>
#include <sys/capsicum.h>
#include <capsicum_helpers.h>
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h>
#include <limits.h> #include <limits.h>
#include <locale.h> #include <locale.h>
#include <stdio.h> #include <stdio.h>
@@ -45,11 +48,14 @@
#include <unistd.h> #include <unistd.h>
#include <wchar.h> #include <wchar.h>
#include <libcasper.h>
#include <casper/cap_fileargs.h>
static wchar_t *delim; static wchar_t *delim;
static int delimcnt; static int delimcnt;
static int parallel(char **); static int parallel(char **, fileargs_t *);
static int sequential(char **); static int sequential(char **, fileargs_t *);
static int tr(wchar_t *); static int tr(wchar_t *);
static void usage(void) __dead2; static void usage(void) __dead2;
@@ -62,6 +68,8 @@ main(int argc, char *argv[])
wchar_t *warg; wchar_t *warg;
const char *arg; const char *arg;
size_t len; size_t len;
fileargs_t *fa;
cap_rights_t rights;
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
@@ -99,8 +107,18 @@ main(int argc, char *argv[])
delim = tab; delim = tab;
} }
rval = seq ? sequential(argv) : parallel(argv); fa = fileargs_init(argc, argv, O_RDONLY, 0,
cap_rights_init(&rights, CAP_READ, CAP_FSTAT, CAP_FCNTL), FA_OPEN);
if (fa == NULL)
err(1, "unable to open system.fileargs service");
caph_cache_catpages();
if (caph_enter_casper() < 0)
err(1, "unable to enter capability mode");
rval = seq ? sequential(argv, fa) : parallel(argv, fa);
fileargs_free(fa);
exit(rval); exit(rval);
} }
@@ -114,7 +132,7 @@ typedef struct _list {
static STAILQ_HEAD(head, _list) lh; static STAILQ_HEAD(head, _list) lh;
static int static int
parallel(char **argv) parallel(char **argv, fileargs_t *fa)
{ {
LIST *lp; LIST *lp;
int cnt; int cnt;
@@ -130,7 +148,7 @@ parallel(char **argv)
err(1, NULL); err(1, NULL);
if (p[0] == '-' && !p[1]) if (p[0] == '-' && !p[1])
lp->fp = stdin; lp->fp = stdin;
else if (!(lp->fp = fopen(p, "r"))) else if (!(lp->fp = fileargs_fopen(fa, p, "r")))
err(1, "%s", p); err(1, "%s", p);
lp->cnt = cnt; lp->cnt = cnt;
lp->name = p; lp->name = p;
@@ -181,7 +199,7 @@ parallel(char **argv)
} }
static int static int
sequential(char **argv) sequential(char **argv, fileargs_t *fa)
{ {
FILE *fp; FILE *fp;
int cnt, failed, needdelim; int cnt, failed, needdelim;
@@ -192,7 +210,7 @@ sequential(char **argv)
for (; (p = *argv); ++argv) { for (; (p = *argv); ++argv) {
if (p[0] == '-' && !p[1]) if (p[0] == '-' && !p[1])
fp = stdin; fp = stdin;
else if (!(fp = fopen(p, "r"))) { else if (!(fp = fileargs_fopen(fa, p, "r"))) {
warn("%s", p); warn("%s", p);
failed = 1; failed = 1;
continue; continue;