]> git.pond.sub.org Git - empserver/commitdiff
(redir_authorized): New, factored out of users in prepraration of next
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 18 Nov 2007 09:32:16 +0000 (09:32 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 18 Nov 2007 09:32:16 +0000 (09:32 +0000)
changeset.
(doredir, dopipe, doexecute): Use it.

src/client/servcmd.c

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