Index: head/bin/echo/echo.c =================================================================== --- head/bin/echo/echo.c (revision 308431) +++ head/bin/echo/echo.c (revision 308432) @@ -1,137 +1,142 @@ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char const copyright[] = "@(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)echo.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include +#include +#include #include #include #include #include #include /* * Report an error and exit. * Use it instead of err(3) to avoid linking-in stdio. */ static __dead2 void errexit(const char *prog, const char *reason) { char *errstr = strerror(errno); write(STDERR_FILENO, prog, strlen(prog)); write(STDERR_FILENO, ": ", 2); write(STDERR_FILENO, reason, strlen(reason)); write(STDERR_FILENO, ": ", 2); write(STDERR_FILENO, errstr, strlen(errstr)); write(STDERR_FILENO, "\n", 1); exit(1); } int main(int argc, char *argv[]) { int nflag; /* if not set, output a trailing newline. */ int veclen; /* number of writev arguments. */ struct iovec *iov, *vp; /* Elements to write, current element. */ char space[] = " "; 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; --argc; nflag = 1; } else nflag = 0; veclen = (argc >= 2) ? (argc - 2) * 2 + 1 : 0; if ((vp = iov = malloc((veclen + 1) * sizeof(struct iovec))) == NULL) errexit(progname, "malloc"); while (argv[0] != NULL) { size_t len; len = strlen(argv[0]); /* * If the next argument is NULL then this is this * the last argument, therefore we need to check * for a trailing \c. */ if (argv[1] == NULL) { /* is there room for a '\c' and is there one? */ if (len >= 2 && argv[0][len - 2] == '\\' && argv[0][len - 1] == 'c') { /* chop it and set the no-newline flag. */ len -= 2; nflag = 1; } } vp->iov_base = *argv; vp++->iov_len = len; if (*++argv) { vp->iov_base = space; vp++->iov_len = 1; } } if (!nflag) { veclen++; vp->iov_base = newline; vp++->iov_len = 1; } /* assert(veclen == (vp - iov)); */ while (veclen) { int nwrite; nwrite = (veclen > IOV_MAX) ? IOV_MAX : veclen; if (writev(STDOUT_FILENO, iov, nwrite) == -1) errexit(progname, "write"); iov += nwrite; veclen -= nwrite; } return 0; } Index: head/bin/sleep/sleep.c =================================================================== --- head/bin/sleep/sleep.c (revision 308431) +++ head/bin/sleep/sleep.c (revision 308432) @@ -1,109 +1,113 @@ /*- * Copyright (c) 1988, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char const copyright[] = "@(#) Copyright (c) 1988, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)sleep.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); +#include #include #include #include #include #include #include #include #include #include static void usage(void); static volatile sig_atomic_t report_requested; static void report_request(int signo __unused) { report_requested = 1; } int main(int argc, char *argv[]) { struct timespec time_to_sleep; double d; time_t original; char buf[2]; + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); if (argc != 2) usage(); if (sscanf(argv[1], "%lf%1s", &d, buf) != 1) usage(); if (d > INT_MAX) usage(); if (d <= 0) return (0); original = time_to_sleep.tv_sec = (time_t)d; time_to_sleep.tv_nsec = 1e9 * (d - time_to_sleep.tv_sec); signal(SIGINFO, report_request); /* * Note: [EINTR] is supposed to happen only when a signal was handled * but the kernel also returns it when a ptrace-based debugger * attaches. This is a bug but it is hard to fix. */ while (nanosleep(&time_to_sleep, &time_to_sleep) != 0) { if (report_requested) { /* Reporting does not bother with nanoseconds. */ warnx("about %d second(s) left out of the original %d", (int)time_to_sleep.tv_sec, (int)original); report_requested = 0; } else if (errno != EINTR) err(1, "nanosleep"); } return (0); } static void usage(void) { fprintf(stderr, "usage: sleep seconds\n"); exit(1); } Index: head/usr.bin/basename/basename.c =================================================================== --- head/usr.bin/basename/basename.c (revision 308431) +++ head/usr.bin/basename/basename.c (revision 308432) @@ -1,143 +1,147 @@ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1991, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif #if 0 #ifndef lint static char sccsid[] = "@(#)basename.c 8.4 (Berkeley) 5/4/95"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); +#include #include #include #include #include #include #include #include #include #include void stripsuffix(char *, const char *, size_t); void usage(void); int main(int argc, char **argv) { char *p, *suffix; size_t suffixlen; int aflag, ch; setlocale(LC_ALL, ""); + + if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) + err(1, "capsicum"); aflag = 0; suffix = NULL; suffixlen = 0; while ((ch = getopt(argc, argv, "as:")) != -1) switch(ch) { case 'a': aflag = 1; break; case 's': suffix = optarg; break; case '?': default: usage(); } argc -= optind; argv += optind; if (argc < 1) usage(); if (!*argv[0]) { printf("\n"); exit(0); } if ((p = basename(argv[0])) == NULL) err(1, "%s", argv[0]); if ((suffix == NULL && !aflag) && argc == 2) { suffix = argv[1]; argc--; } if (suffix != NULL) suffixlen = strlen(suffix); while (argc--) { if ((p = basename(*argv)) == NULL) err(1, "%s", argv[0]); stripsuffix(p, suffix, suffixlen); argv++; (void)printf("%s\n", p); } exit(0); } void stripsuffix(char *p, const char *suffix, size_t suffixlen) { char *q, *r; mbstate_t mbs; size_t n; if (suffixlen && (q = strchr(p, '\0') - suffixlen) > p && strcmp(suffix, q) == 0) { /* Ensure that the match occurred on a character boundary. */ memset(&mbs, 0, sizeof(mbs)); for (r = p; r < q; r += n) { n = mbrlen(r, MB_LEN_MAX, &mbs); if (n == (size_t)-1 || n == (size_t)-2) { memset(&mbs, 0, sizeof(mbs)); n = 1; } } /* Chop off the suffix. */ if (q == r) *q = '\0'; } } void usage(void) { (void)fprintf(stderr, "usage: basename string [suffix]\n" " basename [-a] [-s suffix] string [...]\n"); exit(1); } Index: head/usr.bin/dc/dc.c =================================================================== --- head/usr.bin/dc/dc.c (revision 308431) +++ head/usr.bin/dc/dc.c (revision 308432) @@ -1,140 +1,156 @@ /* $OpenBSD: dc.c,v 1.11 2009/10/27 23:59:37 deraadt Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek * Copyright (c) 2009, Gabor Kovesdan * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include __FBSDID("$FreeBSD$"); #include +#include #include #include #include +#include #include #include #include #include #include #include "extern.h" #define DC_VER "1.3-FreeBSD" static void usage(void); extern char *__progname; static struct source src; static const struct option long_options[] = { {"expression", required_argument, NULL, 'e'}, {"file", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'} }; static void usage(void) { fprintf(stderr, "usage: %s [-hVx] [-e expression] [file]\n", __progname); exit(1); } 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) err(1, "%s", fname); if (S_ISDIR(st.st_mode)) { errno = EISDIR; err(1, "%s", fname); } src_setstream(&src, file); reset_bmachine(&src); eval(); fclose(file); } 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 */ while ((ch = getopt_long(argc, argv, "e:f:hVx", long_options, NULL)) != -1) { switch (ch) { case 'e': if (!preproc_done) init_bmachine(extended_regs); src_setstring(&src, optarg); reset_bmachine(&src); eval(); preproc_done = true; break; 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': extended_regs = true; break; case 'V': fprintf(stderr, "%s (BSD bc) %s\n", __progname, DC_VER); exit(0); break; case '-': break; case 'h': /* FALLTHROUGH */ default: usage(); } } argc -= optind; argv += optind; if (!preproc_done) init_bmachine(extended_regs); setlinebuf(stdout); setlinebuf(stderr); 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(); return (0); } Index: head/usr.bin/dirname/dirname.c =================================================================== --- head/usr.bin/dirname/dirname.c (revision 308431) +++ head/usr.bin/dirname/dirname.c (revision 308432) @@ -1,83 +1,87 @@ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1991, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static const char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95"; #endif /* not lint */ #include __FBSDID("$FreeBSD$"); +#include #include #include #include #include #include void usage(void); int 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 '?': default: usage(); } argc -= optind; argv += optind; if (argc < 1) usage(); while (argc--) { if ((p = dirname(*argv)) == NULL) err(1, "%s", *argv); argv++; (void)printf("%s\n", p); } exit(0); } void usage(void) { (void)fprintf(stderr, "usage: dirname string [...]\n"); exit(1); } Index: head/usr.bin/fold/fold.c =================================================================== --- head/usr.bin/fold/fold.c (revision 308431) +++ head/usr.bin/fold/fold.c (revision 308432) @@ -1,235 +1,239 @@ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Kevin Ruddy. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1990, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)fold.c 8.1 (Berkeley) 6/6/93"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); +#include #include #include #include #include #include #include #include #include #include #define DEFLINEWIDTH 80 void fold(int); static int newpos(int, wint_t); static void usage(void); static int bflag; /* Count bytes, not columns */ static int sflag; /* Split on word boundaries */ int main(int argc, char **argv) { int ch, previous_ch; int rval, width; (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) { switch (ch) { case 'b': bflag = 1; break; case 's': sflag = 1; break; case 'w': if ((width = atoi(optarg)) <= 0) { errx(1, "illegal width value"); } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* Accept a width as eg. -30. Note that a width * specified using the -w option is always used prior * to this undocumented option. */ switch (previous_ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* The width is a number with multiple digits: * add the last one. */ width = width * 10 + (ch - '0'); break; default: /* Set the width, unless it was previously * set. For instance, the following options * would all give a width of 5 and not 10: * -10 -w5 * -5b10 * -5 -10b */ if (width == -1) width = ch - '0'; break; } break; default: usage(); } previous_ch = ch; } argv += optind; argc -= optind; if (width == -1) width = DEFLINEWIDTH; rval = 0; if (!*argv) fold(width); else for (; *argv; ++argv) if (!freopen(*argv, "r", stdin)) { warn("%s", *argv); rval = 1; } else fold(width); exit(rval); } static void usage(void) { (void)fprintf(stderr, "usage: fold [-bs] [-w width] [file ...]\n"); exit(1); } /* * Fold the contents of standard input to fit within WIDTH columns (or bytes) * and write to standard output. * * If sflag is set, split the line at the last space character on the line. * This flag necessitates storing the line in a buffer until the current * column > width, or a newline or EOF is read. * * The buffer can grow larger than WIDTH due to backspaces and carriage * returns embedded in the input stream. */ void fold(int width) { static wchar_t *buf; static int buf_max; int col, i, indx, space; wint_t ch; col = indx = 0; while ((ch = getwchar()) != WEOF) { if (ch == '\n') { wprintf(L"%.*ls\n", indx, buf); col = indx = 0; continue; } if ((col = newpos(col, ch)) > width) { if (sflag) { i = indx; while (--i >= 0 && !iswblank(buf[i])) ; space = i; } if (sflag && space != -1) { space++; wprintf(L"%.*ls\n", space, buf); wmemmove(buf, buf + space, indx - space); indx -= space; col = 0; for (i = 0; i < indx; i++) col = newpos(col, buf[i]); } else { wprintf(L"%.*ls\n", indx, buf); col = indx = 0; } col = newpos(col, ch); } if (indx + 1 > buf_max) { buf_max += LINE_MAX; buf = realloc(buf, sizeof(*buf) * buf_max); if (buf == NULL) err(1, "realloc()"); } buf[indx++] = ch; } if (indx != 0) wprintf(L"%.*ls", indx, buf); } /* * Update the current column position for a character. */ static int newpos(int col, wint_t ch) { char buf[MB_LEN_MAX]; size_t len; int w; if (bflag) { len = wcrtomb(buf, ch, NULL); col += len; } else switch (ch) { case '\b': if (col > 0) --col; break; case '\r': col = 0; break; case '\t': col = (col + 8) & ~7; break; default: if ((w = wcwidth(ch)) > 0) col += w; break; } return (col); } Index: head/usr.bin/getopt/getopt.c =================================================================== --- head/usr.bin/getopt/getopt.c (revision 308431) +++ head/usr.bin/getopt/getopt.c (revision 308432) @@ -1,37 +1,43 @@ #include __FBSDID("$FreeBSD$"); /* * This material, written by Henry Spencer, was released by him * into the public domain and is thus not subject to any copyright. */ +#include +#include +#include #include #include #include int 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) { case '?': status = 1; /* getopt routine gave message */ break; default: if (optarg != NULL) printf(" -%c %s", c, optarg); else printf(" -%c", c); break; } printf(" --"); for (; optind < argc; optind++) printf(" %s", argv[optind]); printf("\n"); return status; } Index: head/usr.bin/locate/bigram/locate.bigram.c =================================================================== --- head/usr.bin/locate/bigram/locate.bigram.c (revision 308431) +++ head/usr.bin/locate/bigram/locate.bigram.c (revision 308432) @@ -1,112 +1,118 @@ /* * Copyright (c) 1995 Wolfram Schneider . Berlin. * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * James A. Woods. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #if 0 #ifndef lint static char copyright[] = "@(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)locate.bigram.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #endif /* * bigram < sorted_file_names | sort -nr | * awk 'NR <= 128 { printf $2 }' > bigrams * * List bigrams for 'updatedb' script. * Use 'code' to encode a file using this output. */ +#include +#include +#include #include #include #include /* for MAXPATHLEN */ #include "locate.h" u_char buf1[MAXPATHLEN] = " "; u_char buf2[MAXPATHLEN]; u_int bigram[UCHAR_MAX + 1][UCHAR_MAX + 1]; int main(void) { u_char *cp; 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) { /* * We don't need remove newline character '\n'. * '\n' is less than ASCII_MIN and will be later * ignored at output. */ /* skip longest common prefix */ for (cp = path; *cp == *oldpath; cp++, oldpath++) if (*cp == '\0') break; while (*cp != '\0' && *(cp + 1) != '\0') { bigram[(u_char)*cp][(u_char)*(cp + 1)]++; cp += 2; } /* swap pointers */ if (path == buf1) { path = buf2; oldpath = buf1; } else { path = buf1; oldpath = buf2; } } /* output, boundary check */ for (i = ASCII_MIN; i <= ASCII_MAX; i++) for (j = ASCII_MIN; j <= ASCII_MAX; j++) if (bigram[i][j] != 0) (void)printf("%4u %c%c\n", bigram[i][j], i, j); exit(0); } Index: head/usr.bin/logname/logname.c =================================================================== --- head/usr.bin/logname/logname.c (revision 308431) +++ head/usr.bin/logname/logname.c (revision 308432) @@ -1,67 +1,71 @@ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1991, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static const char sccsid[] = "@(#)logname.c 8.2 (Berkeley) 4/3/94"; #endif /* not lint */ #include __FBSDID("$FreeBSD$"); +#include #include #include #include #include void usage(void); int 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) err(1, NULL); (void)printf("%s\n", p); exit(0); } void usage(void) { (void)fprintf(stderr, "usage: logname\n"); exit(1); } Index: head/usr.bin/printenv/printenv.c =================================================================== --- head/usr.bin/printenv/printenv.c (revision 308431) +++ head/usr.bin/printenv/printenv.c (revision 308432) @@ -1,99 +1,104 @@ /*- * Copyright (c) 1987, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1987, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #if 0 #ifndef lint static char sccsid[] = "@(#)printenv.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include +#include +#include #include #include #include #include void usage(void); extern char **environ; /* * printenv * * Bill Joy, UCB * February, 1979 */ int main(int argc, char *argv[]) { char *cp, **ep; 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 '?': default: usage(); } argc -= optind; argv += optind; if (argc == 0) { for (ep = environ; *ep; ep++) (void)printf("%s\n", *ep); exit(0); } len = strlen(*argv); for (ep = environ; *ep; ep++) if (!memcmp(*ep, *argv, len)) { cp = *ep + len; if (*cp == '=') { (void)printf("%s\n", cp + 1); exit(0); } } exit(1); } void usage(void) { (void)fprintf(stderr, "usage: printenv [name]\n"); exit(1); } Index: head/usr.bin/yes/yes.c =================================================================== --- head/usr.bin/yes/yes.c (revision 308431) +++ head/usr.bin/yes/yes.c (revision 308432) @@ -1,58 +1,63 @@ /* * Copyright (c) 1987, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1987, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)yes.c 8.1 (Berkeley) 6/6/93"; #else 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) ; else while (puts("y") != EOF) ; err(1, "stdout"); /*NOTREACHED*/ }