00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include <unistd.h>
00022
00023
00024 #define MAXOPTS 16
00025
00026 #define TRY(exp) do { \
00027 if ((exp) == -1) { \
00028 fprintf(stderr, "%s:%d: '%s' failed: ", \
00029 __FILE__, \
00030 __LINE__, \
00031 #exp \
00032 ); perror(NULL); \
00033 exit(81); \
00034 } \
00035 } while(0)
00036
00037
00038 int main(int argc, char **argv)
00039 {
00040 char *options[MAXOPTS];
00041 char *val = NULL;
00042 int opt = 0;
00043
00044 pid_t childpid;
00045 int pfds[2];
00046
00047
00048 #ifdef HAVE_QMAIL_RELAYCLIENT
00049
00050
00051
00052 if (getenv("RELAYCLIENT")) {
00053 TRY(execlp("qmail-queue", "qmail-queue", NULL));
00054 }
00055 #endif
00056
00057
00058
00059 options[opt++] = "spamc";
00060 if ((val = getenv("SPAMDSOCK")) != NULL) {
00061 options[opt++] = "-U";
00062 options[opt++] = val;
00063 }
00064 if ((val = getenv("SPAMDHOST")) != NULL) {
00065 options[opt++] = "-d";
00066 options[opt++] = val;
00067 }
00068 if ((val = getenv("SPAMDPORT")) != NULL) {
00069 options[opt++] = "-p";
00070 options[opt++] = val;
00071 }
00072 if ((val = getenv("SPAMDSSL")) != NULL) {
00073 options[opt++] = "-S";
00074 }
00075 if ((val = getenv("SPAMDLIMIT")) != NULL) {
00076 options[opt++] = "-s";
00077 options[opt++] = val;
00078 }
00079 if ((val = getenv("SPAMDUSER")) != NULL) {
00080 options[opt++] = "-u";
00081 options[opt++] = val;
00082 }
00083 options[opt] = NULL;
00084
00085
00086 TRY(pipe(pfds));
00087 TRY(childpid = fork());
00088 if (childpid == 0) {
00089 TRY(close(1));
00090 TRY(dup(pfds[1]));
00091 TRY(close(pfds[0]));
00092 TRY(execvp("spamc", options));
00093 }
00094 else {
00095 TRY(close(0));
00096 TRY(dup(pfds[0]));
00097 TRY(close(pfds[1]));
00098 TRY(execlp("qmail-queue", "qmail-queue", NULL));
00099 }
00100
00101
00102 return 81;
00103 }
00104