summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/filters.conf2
-rw-r--r--tools/hi-q.c37
-rw-r--r--tools/makefile1
-rwxr-xr-xtools/qmail212
4 files changed, 123 insertions, 129 deletions
diff --git a/tools/filters.conf b/tools/filters.conf
index d255445..61e892a 100644
--- a/tools/filters.conf
+++ b/tools/filters.conf
@@ -1,3 +1,3 @@
# configuration file for hi-q
- /usr/local/bin/spamc -Z 7
+# /usr/local/bin/spamc -Z 7
/var/qmail/bin/qmail-queue
diff --git a/tools/hi-q.c b/tools/hi-q.c
index 0f7e444..f0e107a 100644
--- a/tools/hi-q.c
+++ b/tools/hi-q.c
@@ -134,16 +134,8 @@ int main(int argc, char** argv, char const * const * env) {
#endif
- const char* spamc_args[] = {"/usr/local/bin/spamc", "-Z", "7", 0};
- const char* qq_args[] = {"/var/qmail/bin/qmail-queue", 0};
- const char** joblist[] = {
- spamc_args,
- qq_args,
- 0 // required: zero terminates the list
- };
-
typedef vector<string> VS;
- vector<VS> filters;
+ vector<VS> filter;
if (argc != 2) {
cerr << "Usage: hi-q filter.conf" << endl;
exit(1);
@@ -169,10 +161,10 @@ int main(int argc, char** argv, char const * const * env) {
if (token[0] == '#') break;
job.push_back(token);
}
- if (job.size()) filters.push_back(job);
+ if (job.size()) filter.push_back(job);
}
- if (verbose) for (vector<VS>::const_iterator job = filters.begin();
- job != filters.end(); job++) {
+ if (verbose) for (vector<VS>::const_iterator job = filter.begin();
+ job != filter.end(); job++) {
for (VS::const_iterator token = job->begin();
token != job->end(); token++){
cerr << *token << " ";
@@ -180,21 +172,18 @@ int main(int argc, char** argv, char const * const * env) {
cerr << endl;
}
- int nkids;
- pid_t* kidpid; // indexed by kid number
-
- for (nkids = 0; joblist[nkids]; nkids++) {} // count 'em
- kidpid = (pid_t*) malloc(nkids * sizeof(pid_t));
+ int nkids = filter.size();
+ vector<pid_t> kidpid(nkids); // indexed by kid number
-// At this point, there is some loop invariants;
+// At this point, there are some loop invariants;
// (a) fd0 is open and ready for the next child to read, and
// (b) fd1 is open but is something children can (and should)
// throw away as soon as convenient.
- {int ii; for (ii=0; joblist[ii]; ii++){ /* loop over all kids */
+ {int ii; for (ii=0; ii < nkids; ii++){ /* loop over all kids */
int datapipe[2];
int kid_end;
- int lastkid = !joblist[ii+1];
+ int lastkid = (ii == nkids-1);
#define flip(a,b) (lastkid ? b : a)
//xx fprintf(stderr, "Top of loop %d loose: %d\n", ii, loose_end);
@@ -222,7 +211,6 @@ int main(int argc, char** argv, char const * const * env) {
kidpid[ii] = fork();
if (!kidpid[ii]) { /*** child code ***/
- const char ** prog;
// Now that we are through creating pipes, get rid
// of the placeholder:
@@ -242,7 +230,12 @@ int main(int argc, char** argv, char const * const * env) {
// and write fd1 (except last kid reads fd1).
//// probe_fd();
- prog = joblist[ii];
+ int ntok = filter[ii].size();
+ const char* prog[1+ntok];
+ for (int jj = 0; jj < ntok; jj++){
+ prog[jj] = filter[ii][jj].c_str();
+ }
+ prog[ntok] = 0;
rslt = Execve(prog[0], prog, env);
fprintf(stderr, "hi-q: failed to exec '%s': ", prog[0]);
perror(0);
diff --git a/tools/makefile b/tools/makefile
index e87fa57..db0cde2 100644
--- a/tools/makefile
+++ b/tools/makefile
@@ -14,6 +14,7 @@ all: pido hi-q
install:
install pido hi-q /var/qmail/bin/
+ cp filters.conf /var/qmail/control/
/etc/tcpserver/smtp.rules :
install -d /etc/tcpserver
diff --git a/tools/qmail b/tools/qmail
index 9b715ee..e49ac96 100755
--- a/tools/qmail
+++ b/tools/qmail
@@ -127,128 +127,128 @@ fi
flag=""
case "$verb" in
- restart)
- $0 stop $@
- $0 start $@
- ;;
- start)
- if test -n "${send%%[Nn0]*}" ; then
- test -n "$banner" && echo $banner ; banner=""
- proc=qmail-send
- if proc_running $proc ; then
+ restart)
+ $0 stop $@
+ $0 start $@
+ ;;
+ start)
+ if test -n "${send%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-send
+ if proc_running $proc ; then
+ 1>&2 echo " Oops, $proc is already running ($pid)."
+ else
+ echo -n " qmail-send: "
+ /bin/rm -f /var/run/$proc.pid
+ qmail-start ./Maildir/ splogger qmail >/dev/null 2>&1 &
+ echo $! > /var/run/$proc.pid
+ proc_ok $proc
+ fi
+ fi
+
+ if test -n "${smtp%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-smtp
+ if proc_running $proc ; then
+ 1>&2 echo " Oops, $proc is already running ($pid)."
+ else
+ echo -n " SMTP-server "
+ /bin/rm -f /var/run/$proc.pid
+ QMAILQUEUE="/var/qmail/bin/hi-q asdf/var/qmail/control/filters.conf" \
+ $PIDO /var/run/$proc.pid \
+ $tcps -R -x/etc/tcpserver/smtp.cdb \
+ -u$qmaild -g$nofiles $mailhost smtp \
+ qmail-smtpd 2>&1 \
+ | splogger smtp &
+ proc_ok $proc
+ fi
+ fi
+
+ if test -n "${smtps%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-smtps
+ if proc_running $proc ; then
1>&2 echo " Oops, $proc is already running ($pid)."
- else
- echo -n " qmail-send: "
+ else
+ echo -n " SMTPS-server "
/bin/rm -f /var/run/$proc.pid
- qmail-start ./Maildir/ splogger qmail >/dev/null 2>&1 &
- echo $! > /var/run/$proc.pid
+ $PIDO /var/run/$proc.pid \
+ $tcps -R -u$qmaild -g$nofiles $mailhost smtps \
+ stunnel4 $smtpconf 2>&1 \
+ | splogger smtps &
proc_ok $proc
- fi
fi
+ fi
+
- if test -n "${smtp%%[Nn0]*}" ; then
- test -n "$banner" && echo $banner ; banner=""
- proc=qmail-smtp
- if proc_running $proc ; then
+ if test -n "${pop3%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-pop3
+ if proc_running $proc ; then
1>&2 echo " Oops, $proc is already running ($pid)."
- else
- echo -n " SMTP-server "
+ else
+ echo -n " POP3-server "
/bin/rm -f /var/run/$proc.pid
- ## xxxQMAILQUEUE=/var/qmail/bin/hi-q \
$PIDO /var/run/$proc.pid \
- $tcps -R -x/etc/tcpserver/smtp.cdb \
- -u$qmaild -g$nofiles $mailhost smtp \
- qmail-smtpd 2>&1 \
- | splogger smtp &
+ $tcps -v -p -R $mailhost pop3 qmail-popup $mailhost \
+ $CKPW qmail-pop3d Maildir 2>&1 \
+ | splogger pop3 &
proc_ok $proc
- fi
- fi
-
- if test -n "${smtps%%[Nn0]*}" ; then
- test -n "$banner" && echo $banner ; banner=""
- proc=qmail-smtps
- if proc_running $proc ; then
- 1>&2 echo " Oops, $proc is already running ($pid)."
- else
- echo -n " SMTPS-server "
- /bin/rm -f /var/run/$proc.pid
- $PIDO /var/run/$proc.pid \
- $tcps -R -u$qmaild -g$nofiles $mailhost smtps \
- stunnel $smtpconf 2>&1 \
- | splogger smtps &
- proc_ok $proc
- fi
- fi
-
-
- if test -n "${pop3%%[Nn0]*}" ; then
- test -n "$banner" && echo $banner ; banner=""
- proc=qmail-pop3
- if proc_running $proc ; then
- 1>&2 echo " Oops, $proc is already running ($pid)."
- else
- echo -n " POP3-server "
- /bin/rm -f /var/run/$proc.pid
- $PIDO /var/run/$proc.pid \
- $tcps -v -p -R $mailhost pop3 qmail-popup $mailhost \
- $CKPW qmail-pop3d Maildir 2>&1 \
- | splogger pop3 &
- proc_ok $proc
- fi
fi
+ fi
- if test -n "${pop3s%%[Nn0]*}" ; then
- test -n "$banner" && echo $banner ; banner=""
- proc=qmail-pop3s
- if proc_running $proc ; then
- 1>&2 echo " Oops, $proc is already running ($pid)."
- else
- echo -n " POP3S-server "
- /bin/rm -f /var/run/$proc.pid
- $PIDO /var/run/$proc.pid \
- $tcps -v -p -R $mailhost pop3s \
- stunnel $pop3conf 2>&1 | \
- splogger pop3s &
- proc_ok $proc
- fi
+ if test -n "${pop3s%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-pop3s
+ if proc_running $proc ; then
+ 1>&2 echo " Oops, $proc is already running ($pid)."
+ else
+ echo -n " POP3S-server "
+ /bin/rm -f /var/run/$proc.pid
+ $PIDO /var/run/$proc.pid \
+ $tcps -v -p -R $mailhost pop3s \
+ stunnel4 $pop3conf 2>&1 | \
+ splogger pop3s &
+ proc_ok $proc
fi
- ;;
+ fi
+ ;;
- zap)
- stop_all "-"
- ;;
+ zap)
+ stop_all "-"
+ ;;
- stop)
- stop_all ""
- ;;
+ stop)
+ stop_all ""
+ ;;
## cause qmail-send to reread a couple of control files:
- reload)
- echo -n "Reread control/locals, control/rcpthosts, and control/virtualdomains: "
- if kill -1 $( cat /var/run/qmail-send.pid ) ; then
- echo " ok."
- else
- echo " failed."
- fi
- ;;
- status)
- for thing in send smtp smtps pop3 pop3s ; do
- xthing="qmail-$thing"
- printf "%-12s : " "$xthing"
- pid=$( cat /var/run/$xthing.pid 2>/dev/null )
- : ${pid:=xxx}
- if kill -0 "$pid" 2>/dev/null ; then
- echo " up. $pid"
+ reload)
+ echo -n "Reread control/locals, control/rcpthosts, and control/virtualdomains: "
+ if kill -1 $( cat /var/run/qmail-send.pid ) ; then
+ echo " ok."
else
- echo " down. $pid"
+ echo " failed."
fi
- done
- if ! test -r '/etc/tcpserver/smtp.cdb' ; then
- echo "Beware: /etc/tcpserver/smtp.cdb is missing."
- fi
- ;;
- *)
- echo "Usage: $0 {start|stop|reload|zap|restart|status}"
- exit 1
- ;;
+ ;;
+ status)
+ for thing in send smtp smtps pop3 pop3s ; do
+ xthing="qmail-$thing"
+ printf "%-12s : " "$xthing"
+ pid=$( cat /var/run/$xthing.pid 2>/dev/null )
+ : ${pid:=xxx}
+ if kill -0 "$pid" 2>/dev/null ; then
+ echo " up. $pid"
+ else
+ echo " down. $pid"
+ fi
+ done
+ if ! test -r '/etc/tcpserver/smtp.cdb' ; then
+ echo "Beware: /etc/tcpserver/smtp.cdb is missing."
+ fi
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|reload|zap|restart|status}"
+ exit 1
+ ;;
esac