Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F141901599
D8076.id20816.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D8076.id20816.diff
View Options
Index: usr.bin/lam/lam.c
===================================================================
--- usr.bin/lam/lam.c
+++ usr.bin/lam/lam.c
@@ -46,11 +46,17 @@
* Author: John Kunze, UCB
*/
+#include <sys/capsicum.h>
+
#include <ctype.h>
#include <err.h>
+#include <errno.h>
+#include <nl_types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
+#include <unistd.h>
#define MAXOFILES 20
#define BIGBUFSIZ 5 * BUFSIZ
@@ -78,12 +84,44 @@
main(int argc, char *argv[])
{
struct openfile *ip;
+ cap_rights_t rights;
+ unsigned long cmd;
if (argc == 1)
usage();
+
+ /* XXX: Replace with new capsicum helper once it is available */
+ cap_rights_init(&rights, CAP_FSTAT, CAP_IOCTL, CAP_READ);
+ if (cap_rights_limit(STDIN_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for stdin");
+ cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE, CAP_IOCTL);
+ if (cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for stdout");
+ if (cap_rights_limit(STDERR_FILENO, &rights) < 0 && errno != ENOSYS)
+ err(1, "unable to limit rights for stderr");
+
+ /* Required for printf(3) via isatty(3). */
+ cmd = TIOCGETA;
+ if (cap_ioctls_limit(STDIN_FILENO, &cmd, 1) < 0 && errno != ENOSYS)
+ err(1, "unable to limit ioctls for stdin");
+ if (cap_ioctls_limit(STDOUT_FILENO, &cmd, 1) < 0 && errno != ENOSYS)
+ err(1, "unable to limit ioctls for stdout");
+ if (cap_ioctls_limit(STDERR_FILENO, &cmd, 1) < 0 && errno != ENOSYS)
+ err(1, "unable to limit ioctls for stderr");
+
+ /*
+ * Cache NLS data, for strerror, for err(3), before entering capability
+ * mode.
+ */
+ (void)catopen("libc", NL_CAT_LOCALE);
+
getargs(argv);
if (!morefiles)
usage();
+
+ if (cap_enter() < 0 && errno != ENOSYS)
+ err(1, "unable to enter capability mode");
+
for (;;) {
linep = line;
for (ip = input; ip->fp != NULL; ip++)
@@ -105,6 +143,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) {
@@ -116,6 +157,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 : "");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 13, 6:21 AM (13 h, 29 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27625276
Default Alt Text
D8076.id20816.diff (2 KB)
Attached To
Mode
D8076: Capsicum-ize lam(1)
Attached
Detach File
Event Timeline
Log In to Comment