Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F139424045
D7918.id21562.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D7918.id21562.diff
View Options
Index: usr.bin/ident/ident.c
===================================================================
--- usr.bin/ident/ident.c
+++ usr.bin/ident/ident.c
@@ -28,11 +28,14 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/capsicum.h>
#include <sys/types.h>
#include <sys/sbuf.h>
+#include <capsicum_helpers.h>
#include <ctype.h>
#include <err.h>
+#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -202,8 +205,9 @@
main(int argc, char **argv)
{
bool quiet = false;
- int ch, i;
+ int ch, i, *fds, fd;
int ret = EXIT_SUCCESS;
+ size_t nfds;
FILE *fp;
while ((ch = getopt(argc, argv, "qV")) != -1) {
@@ -223,17 +227,50 @@
argc -= optind;
argv += optind;
- if (argc == 0)
- return (scan(stdin, NULL, quiet));
+ if (caph_limit_stdio() < 0)
+ err(EXIT_FAILURE, "unable to limit stdio");
- for (i = 0; i < argc; i++) {
- fp = fopen(argv[i], "r");
+ if (argc == 0) {
+ nfds = 1;
+ fds = malloc(sizeof(*fds));
+ if (fds == NULL)
+ err(EXIT_FAILURE, "unable to allocate fds array");
+ fds[0] = STDIN_FILENO;
+ } else {
+ nfds = argc;
+ fds = malloc(sizeof(*fds) * nfds);
+ if (fds == NULL)
+ err(EXIT_FAILURE, "unable to allocate fds array");
+
+ for (i = 0; i < argc; i++) {
+ fds[i] = fd = open(argv[i], O_RDONLY);
+ if (fd < 0) {
+ warn("%s", argv[i]);
+ ret = EXIT_FAILURE;
+ continue;
+ }
+ if (caph_limit_stream(fd, CAPH_READ) < 0)
+ err(EXIT_FAILURE,
+ "unable to limit fcntls/rights for %s",
+ argv[i]);
+ }
+ }
+
+ /* Enter Capsicum sandbox. */
+ if (cap_enter() < 0 && errno != ENOSYS)
+ err(EXIT_FAILURE, "unable to enter capability mode");
+
+ for (i = 0; i < (int)nfds; i++) {
+ if (fds[i] < 0)
+ continue;
+
+ fp = fdopen(fds[i], "r");
if (fp == NULL) {
warn("%s", argv[i]);
ret = EXIT_FAILURE;
continue;
}
- if (scan(fp, argv[i], quiet) != EXIT_SUCCESS)
+ if (scan(fp, argc == 0 ? NULL : argv[i], quiet) != EXIT_SUCCESS)
ret = EXIT_FAILURE;
fclose(fp);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 12, 10:29 PM (17 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26914291
Default Alt Text
D7918.id21562.diff (1 KB)
Attached To
Mode
D7918: ident(1): Capsicumify
Attached
Detach File
Event Timeline
Log In to Comment