Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from(1): Capsicumise #1491

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions usr.bin/from/from.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
*/

#include <sys/types.h>
#include <sys/capsicum.h>

#include <ctype.h>
#include <err.h>
kfv marked this conversation as resolved.
Show resolved Hide resolved
#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -55,6 +58,7 @@
#else
char buf[BUFSIZ];
#endif
cap_rights_t rights;

file = sender = NULL;
count = -1;
Expand Down Expand Up @@ -95,12 +99,15 @@
}

/* read from stdin */
if (strcmp(file, "-") == 0) {
if (strcmp(file, "-") == 0)
mbox = stdin;
}
else if ((mbox = fopen(file, "r")) == NULL) {
else if ((mbox = fopen(file, "r")) == NULL)
errx(1, "can't read %s", file);
}
if (cap_enter() < 0 && errno != ENOSYS)
err(EXIT_FAILURE, "failed to enter capability mode");
cap_rights_init(&rights, CAP_READ);
if (cap_rights_limit(fileno(mbox), &rights) < 0 && errno != ENOSYS)
err(EXIT_FAILURE, "unable to limit rights");
for (newline = 1; fgets(buf, sizeof(buf), mbox);) {
if (*buf == '\n') {
newline = 1;
Expand All @@ -119,32 +126,32 @@
printf("There %s %d message%s in your incoming mailbox.\n",
count == 1 ? "is" : "are", count, count == 1 ? "" : "s");
fclose(mbox);
exit(0);
exit(EXIT_SUCCESS);
}

static void
usage(void)
{
fprintf(stderr, "usage: from [-c] [-f file] [-s sender] [user]\n");
exit(1);
exit(EXIT_FAILURE);
}

static int
match(const char *line, const char *sender)
{

Check failure on line 141 in usr.bin/from/from.c

View workflow job for this annotation

GitHub Actions / Style Checker

space required before the open parenthesis '('
char ch, pch, first;
const char *p, *t;

for (first = *sender++;;) {
if (isspace(ch = *line))
return(0);
return(EXIT_SUCCESS);
++line;

Check failure on line 148 in usr.bin/from/from.c

View workflow job for this annotation

GitHub Actions / Style Checker

space required before the open parenthesis '('
ch = tolower(ch);
if (ch != first)
continue;
for (p = sender, t = line;;) {
if (!(pch = *p++))
return(1);
return(EXIT_FAILURE);
ch = tolower(*t);
t++;
if (ch != pch)
Expand Down
Loading