Index: contrib/elftoolchain/strings/strings.c =================================================================== --- contrib/elftoolchain/strings/strings.c +++ contrib/elftoolchain/strings/strings.c @@ -25,8 +25,10 @@ */ #include +#include #include +#include #include #include #include @@ -44,6 +46,9 @@ #include #include +#include +#include + #include "_elftc.h" ELFTC_VCSID("$Id: strings.c 3571 2017-09-14 02:04:50Z emaste $"); @@ -85,7 +90,7 @@ }; long getcharacter(FILE *); -int handle_file(const char *); +int handle_file(fileargs_t *fa, const char *); int handle_elf(const char *, FILE *); int handle_binary(const char *, FILE *, size_t); int find_strings(const char *, FILE *, off_t, off_t); @@ -99,6 +104,8 @@ int main(int argc, char **argv) { + fileargs_t *fa; + cap_rights_t rights; int ch, rc; rc = 0; @@ -187,27 +194,41 @@ argc -= optind; argv += optind; + cap_rights_init(&rights, CAP_READ, CAP_SEEK, CAP_FSTAT, CAP_FCNTL); + fa = fileargs_init(argc, argv, O_RDONLY, 0, &rights); + if (fa == NULL) + err(1, "Unable to enter capability mode"); + + caph_cache_catpages(); + if (caph_limit_stdio() < 0 && caph_enter_casper() < 0) { + fileargs_free(fa); + err(1, "Unable to enter capability mode"); + } + if (min_len == 0) min_len = 4; if (*argv == NULL) rc = find_strings("{standard input}", stdin, 0, 0); else while (*argv != NULL) { - if (handle_file(*argv) != 0) + if (handle_file(fa, *argv) != 0) rc = 1; argv++; } + + fileargs_free(fa); + return (rc); } int -handle_file(const char *name) +handle_file(fileargs_t *fa, const char *name) { FILE *pfile; int rt; if (name == NULL) return (1); - pfile = fopen(name, "rb"); + pfile = fileargs_fopen(fa, name, "rb"); if (pfile == NULL) { warnx("'%s': %s", name, strerror(errno)); return (1); Index: usr.bin/strings/Makefile =================================================================== --- usr.bin/strings/Makefile +++ usr.bin/strings/Makefile @@ -10,6 +10,12 @@ LIBADD= elftc elf +.if ${MK_CASPER} != "no" +LIBADD+= casper +LIBADD+= cap_fileargs +CFLAGS+= -DWITH_CASPER +.endif + CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common .include