Index: head/usr.bin/lam/lam.c =================================================================== --- head/usr.bin/lam/lam.c +++ head/usr.bin/lam/lam.c @@ -46,11 +46,16 @@ * Author: John Kunze, UCB */ +#include + +#include #include #include +#include #include #include #include +#include #define MAXOFILES 20 #define BIGBUFSIZ 5 * BUFSIZ @@ -84,6 +89,17 @@ getargs(argv); if (!morefiles) usage(); + + /* + * Cache NLS data, for strerror, for err(3), before entering capability + * mode. + */ + caph_cache_catpages(); + if (caph_limit_stdio() == -1) + err(1, "unable to limit stdio"); + if (cap_enter() < 0 && errno != ENOSYS) + err(1, "unable to enter capability mode"); + for (;;) { linep = line; for (ip = input; ip->fp != NULL; ip++) @@ -105,7 +121,9 @@ static char fmtbuf[BUFSIZ]; char *fmtp = fmtbuf; int P, S, F, T; + cap_rights_t rights_ro; + cap_rights_init(&rights_ro, CAP_READ, CAP_FSTAT); P = S = F = T = 0; /* capitalized options */ while ((p = *++av) != NULL) { if (*p != '-' || !p[1]) { @@ -116,6 +134,8 @@ else if ((ip->fp = fopen(p, "r")) == NULL) { err(1, "%s", p); } + if (cap_rights_limit(fileno(ip->fp), &rights_ro) < 0) + err(1, "unable to limit rights on: %s", p); ip->pad = P; if (!ip->sepstring) ip->sepstring = (S ? (ip-1)->sepstring : "");