(redir_authorized): New, factored out of users in prepraration of next

changeset.
(doredir, dopipe, doexecute): Use it.
This commit is contained in:
Markus Armbruster 2007-11-18 09:32:16 +00:00
parent 24048a7f12
commit 72b01c8ba1

View file

@ -145,6 +145,17 @@ fname(char *s)
return beg; return beg;
} }
static int
redir_authorized(char *arg, char *attempt)
{
if (!seen_input(arg)) {
fprintf(stderr, "WARNING! Server attempted to %s %s\n",
attempt, arg);
return 0;
}
return 1;
}
/* /*
* opens redir_fp if successful * opens redir_fp if successful
*/ */
@ -159,12 +170,8 @@ doredir(char *p)
redir_fp = NULL; redir_fp = NULL;
} }
if (!seen_input(p)) { if (!redir_authorized(p, "redirect to file"))
fprintf(stderr, "WARNING! Server attempted to redirect %s\n",
p);
return; return;
}
if (*p++ != '>') { if (*p++ != '>') {
fprintf(stderr, "WARNING! Weird redirection %s", p); fprintf(stderr, "WARNING! Weird redirection %s", p);
return; return;
@ -200,11 +207,8 @@ doredir(char *p)
static void static void
dopipe(char *p) dopipe(char *p)
{ {
if (!seen_input(p)) { if (!redir_authorized(p, "pipe to command"))
fprintf(stderr, "WARNING! Server attempted to pipe %s", p);
return; return;
}
if (*p++ != '|') { if (*p++ != '|') {
fprintf(stderr, "WARNING! Weird pipe %s", p); fprintf(stderr, "WARNING! Weird pipe %s", p);
return; return;
@ -227,12 +231,8 @@ doexecute(char *p)
{ {
input_fd = -1; /* make sure play() terminates exec */ input_fd = -1; /* make sure play() terminates exec */
if (!seen_input(p)) { if (!redir_authorized(p, "read file"))
fprintf(stderr,
"WARNING! Server attempted to read file %s",
p);
return; return;
}
p = fname(p); p = fname(p);
if (*p == 0) { if (*p == 0) {