Initial "gts1" commit.
[tac_plus.git] / programs.c
index bce0178..ac42b23 100644 (file)
 
 /* Routines to fork children and communicate with them via pipes */
 
+
 #include "tac_plus.h"
-#include "sys/wait.h"
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#include "signal.h"
+#endif
+#include <signal.h>
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#endif
+#ifdef HAVE_SYS_SYSLOG_H
+#include <sys/syslog.h>
+#endif
+
+#include "programs.h"
+#include "utils.h"
+#include "report.h"
+#include "do_author.h"                 /* for "struct author_data" */
+#include "main.h"
+
 
 /* Support for dollar variables.  Look in the authorization data and
 return strings representing values found there.  If not found, return
@@ -38,6 +57,8 @@ type    -- (1 to 4)
 service -- (1 to 7)
 status  -- (pass, fail, error, unknown) */
 
+static char *lookup TAC_ARGS((char *sym, struct author_data *data));
+
 static char *
 lookup(sym, data)
 char *sym;
@@ -96,12 +117,14 @@ struct author_data *data;
    values for the various $ variables by looking in the authorization
    data */
 
+static char *substitute TAC_ARGS((const char *string, struct author_data *data));
+
 static char *
 substitute(string, data)
-char *string;
+const char *string;
 struct author_data *data;
 {
-    char *cp;
+    const char *cp;
     char out[MAX_INPUT_LINE_LEN], *outp;
     char sym[MAX_INPUT_LINE_LEN], *symp;
     char *value, *valuep;
@@ -129,7 +152,7 @@ struct author_data *data;
 
        } else {
            /* copy symbol into sym */
-           while (*cp && isalpha(*cp))
+           while (*cp && isalpha((int) *cp))
                *symp++ = *cp++;
        }
 
@@ -160,6 +183,8 @@ struct author_data *data;
 /* Wait for a (child) pid to terminate. Return its status. Probably
    horribly implementation dependent. */
 
+static int waitfor TAC_ARGS((int pid));
+
 static int
 waitfor(pid)
 int pid;
@@ -189,6 +214,8 @@ int pid;
     return (WEXITSTATUS(status));
 }
 
+static int write_args TAC_ARGS((int fd, char **args, int arg_cnt));
+
 /* Write an argv array of strings to fd, adding a newline to each one */
 static int
 write_args(fd, args, arg_cnt)
@@ -211,6 +238,8 @@ char **args;
     return (0);
 }
 
+static void close_fds TAC_ARGS((int fd1, int fd2, int fd3));
+
 /* Close the three given file-descruptors */
 static void
 close_fds(fd1, fd2, fd3)
@@ -230,6 +259,8 @@ close_fds(fd1, fd2, fd3)
 /* Fork a command. Return read and write file descriptors in readfdp
    and writefdp. Return the pid or -1 if unsuccessful */
 
+static int my_popen TAC_ARGS((char *cmd, int *readfdp, int *writefdp, int *errorfdp));
+
 static int
 my_popen(cmd, readfdp, writefdp, errorfdp)
 char *cmd;
@@ -240,7 +271,7 @@ int *readfdp, *writefdp, *errorfdp;
 
     fd1[0] = fd1[1] = fd2[0] = fd2[1] = fd3[0] = fd3[1] = -1;
     *readfdp = *writefdp = *errorfdp = -1;
-    
+
     if (pipe(fd1) < 0 || pipe(fd2) < 0 || pipe(fd3) < 0) {
        report(LOG_ERR, "%s: Cannot create pipes", session.peer);
        close_fds(fd1[0], fd2[0], fd3[0]);
@@ -297,6 +328,8 @@ int *readfdp, *writefdp, *errorfdp;
     return(0); /* keep Codecenter quiet */
 }
 
+static int read_string TAC_ARGS((int fd, char *string, int len));
+
 /* read the file descriptor and stuff the data into the given array for
  * the number of bytes given. Throw the rest away.
  */
@@ -305,9 +338,9 @@ read_string (fd, string, len)
 int fd, len;
 char *string;
 {
-    uint i, ret;
+    int i, ret;
     char c;
-    
+
     i=0;
     do {
        ret = read(fd, &c, 1);
@@ -324,6 +357,8 @@ char *string;
    the count of lines seen so far. When eof is read, the array is
    allocated, and the recursion unravels */
 
+static char **read_args TAC_ARGS((int n, int fd));
+
 static char **
 read_args(n, fd)
 int n, fd;
@@ -356,12 +391,16 @@ int n, fd;
    standard input and read its standard output into outarray. Return
    the commands final status when it terminates */
 
+int call_pre_process TAC_ARGS((const char *string, struct author_data *data, char ***outargsp, int *outargs_cntp, char *error, int err_len));
+
 int
 call_pre_process(string, data, outargsp, outargs_cntp, error, err_len)
-char *string, *error;
+const char *string;
 struct author_data *data;
 char ***outargsp;
-int *outargs_cntp, err_len;
+int *outargs_cntp;
+char *error;
+int err_len;
 {
     char **new_args;
     int readfd, writefd, errorfd;
@@ -370,7 +409,7 @@ int *outargs_cntp, err_len;
     int pid = my_popen(cmd, &readfd, &writefd, &errorfd);
 
     memset(error, '\0', err_len);
-    
+
     free(cmd);
 
     if (pid < 0) {
@@ -402,10 +441,10 @@ int *outargs_cntp, err_len;
 
     read_string(errorfd, error, err_len);
     if (error[0] != '\0') {
-       report(LOG_ERR, "Error from program (%d): \"%s\" ",
-              strlen(error), error);
+       report(LOG_ERR, "Error from program (%u): \"%s\" ",
+              (unsigned) strlen(error), error);
     }
-       
+
     /* count the args */
     for (i = 0; new_args[i]; i++)
         /* NULL stmt */ ;
@@ -422,9 +461,11 @@ int *outargs_cntp, err_len;
    standard input and read its standard output into outarray. Return
    the commands final status when it terminates */
 
+int call_post_process TAC_ARGS((const char *string, struct author_data *data, char ***outargsp, int *outargs_cntp));
+
 int
 call_post_process(string, data, outargsp, outargs_cntp)
-char *string;
+const char *string;
 struct author_data *data;
 char ***outargsp;
 int *outargs_cntp;