/* 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
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;
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;
} else {
/* copy symbol into sym */
- while (*cp && isalpha(*cp))
+ while (*cp && isalpha((int) *cp))
*symp++ = *cp++;
}
/* 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;
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)
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)
/* 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;
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]);
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.
*/
int fd, len;
char *string;
{
- uint i, ret;
+ int i, ret;
char c;
-
+
i=0;
do {
ret = read(fd, &c, 1);
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;
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;
int pid = my_popen(cmd, &readfd, &writefd, &errorfd);
memset(error, '\0', err_len);
-
+
free(cmd);
if (pid < 0) {
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 */ ;
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;