Skip to content
Permalink
Browse files

Extract new qmail-qfilter-queue program.

  • Loading branch information...
schmonz committed Nov 26, 2018
1 parent cc9cf06 commit 26188fb8275d62545c025a77227965eb0745b5c9
Showing with 84 additions and 60 deletions.
  1. +16 −9 Makefile
  2. +2 −0 TARGETS
  3. +61 −0 qmail-qfilter-queue.c
  4. +5 −51 qmail-qfilter-smtpd-queue.c
@@ -1341,10 +1341,8 @@ auto_usera.h
./compile qmail-pw2u.c

qmail-qfilter-ofmipd-queue: \
load qmail-qfilter-ofmipd-queue.o control.o error.a fs.a getln.a \
open.a stralloc.a substdio.a str.a alloc.a wait.a
./load qmail-qfilter-ofmipd-queue control.o error.a fs.a getln.a \
open.a stralloc.a substdio.a str.a alloc.a wait.a
load qmail-qfilter-ofmipd-queue.o env.a error.a fs.a str.a alloc.a
./load qmail-qfilter-ofmipd-queue env.a error.a fs.a str.a alloc.a

qmail-qfilter-ofmipd-queue.c: \
qmail-qfilter-smtpd-queue.c
@@ -1353,17 +1351,25 @@ qmail-qfilter-smtpd-queue.c
> qmail-qfilter-ofmipd-queue.c

qmail-qfilter-ofmipd-queue.o: \
compile qmail-qfilter-ofmipd-queue.c control.h stralloc.h wait.h
compile qmail-qfilter-ofmipd-queue.c env.h
./compile qmail-qfilter-ofmipd-queue.c

qmail-qfilter-smtpd-queue: \
load qmail-qfilter-smtpd-queue.o control.o env.a error.a fs.a getln.a \
qmail-qfilter-queue: \
load qmail-qfilter-queue.o control.o env.a error.a fs.a getln.a \
open.a stralloc.a substdio.a str.a alloc.a wait.a
./load qmail-qfilter-smtpd-queue control.o env.a error.a fs.a getln.a \
./load qmail-qfilter-queue control.o env.a error.a fs.a getln.a \
open.a stralloc.a substdio.a str.a alloc.a wait.a

qmail-qfilter-queue.o: \
compile qmail-qfilter-queue.c control.h stralloc.h wait.h
./compile qmail-qfilter-queue.c

qmail-qfilter-smtpd-queue: \
load qmail-qfilter-smtpd-queue.o env.a error.a fs.a str.a alloc.a
./load qmail-qfilter-smtpd-queue env.a error.a fs.a str.a alloc.a

qmail-qfilter-smtpd-queue.o: \
compile qmail-qfilter-smtpd-queue.c control.h stralloc.h wait.h
compile qmail-qfilter-smtpd-queue.c env.h
./compile qmail-qfilter-smtpd-queue.c

qmail-qfilter-viruscan: \
@@ -1805,6 +1811,7 @@ timeoutread.h timeoutwrite.h remoteinfo.h
./compile remoteinfo.c

rejectutils: \
qmail-qfilter-queue \
qmail-qfilter-ofmipd-queue qmail-qfilter-smtpd-queue \
qmail-qfilter-viruscan \
qmail-rcptcheck \
@@ -387,6 +387,8 @@ setup
check
badrcptto.o
case_startb2.o
qmail-qfilter-queue
qmail-qfilter-queue.o
qmail-qfilter-ofmipd-queue
qmail-qfilter-ofmipd-queue.c
qmail-qfilter-ofmipd-queue.o
@@ -0,0 +1,61 @@
#include <unistd.h>
#include "alloc.h"
#include "control.h"
#include "env.h"
#include "str.h"
#include "stralloc.h"
#include "wait.h"

static void unable_to_allocate() { _exit(51); }
static void unable_to_execute() { _exit(71); }
static void unable_to_verify() { _exit(55); }

static int num_lines(stralloc *lines) {
int num = 0;
int i;
for (i = 0; i < lines->len; i++) if (lines->s[i] == '\0') num++;
return num;
}

static void run_qmail_qfilter(stralloc *filters) {
int num_args;
char **args;
int arg;
int linestart;
int i;

num_args = 2 * num_lines(filters);
if (num_args == 0) num_args = 1;
if (!(args = (char **) alloc(sizeof(char *) * num_args)))
unable_to_allocate();

args[0] = "bin/qmail-qfilter";

arg = 0;
linestart = 0;
for (i = 0; i < filters->len; i++) {
if (filters->s[i] == '\0') {
stralloc filter = {0};
stralloc_copys(&filter, filters->s + linestart);
stralloc_0(&filter);
args[++arg] = filter.s;
args[++arg] = "--";
linestart = i + 1;
}
}
args[num_args] = 0;

execv(*args, args);
unable_to_execute();
}

int main(int argc, char **argv) {
stralloc filters = {0};
char *filterfile;

if ((filterfile = env_get("QMAILQUEUEFILTERS")))
if (control_readfile(&filters,filterfile,0) != 1)
unable_to_verify();

run_qmail_qfilter(&filters);
}
@@ -1,61 +1,15 @@
#include <unistd.h>
#include "alloc.h"
#include "control.h"
#include "env.h"
#include "str.h"
#include "stralloc.h"
#include "wait.h"

static void unable_to_allocate() { _exit(51); }
static void unable_to_execute() { _exit(71); }
static void unable_to_verify() { _exit(55); }

static int num_lines(stralloc *lines) {
int num = 0;
int i;
for (i = 0; i < lines->len; i++) if (lines->s[i] == '\0') num++;
return num;
}

static void run_qmail_qfilter(stralloc *filters) {
int num_args;
char **args;
int arg;
int linestart;
int i;

num_args = 2 * num_lines(filters);
if (num_args == 0) num_args = 1;
if (!(args = (char **) alloc(sizeof(char *) * num_args)))
unable_to_allocate();

args[0] = "bin/qmail-qfilter";

arg = 0;
linestart = 0;
for (i = 0; i < filters->len; i++) {
if (filters->s[i] == '\0') {
stralloc filter = {0};
stralloc_copys(&filter, filters->s + linestart);
stralloc_0(&filter);
args[++arg] = filter.s;
args[++arg] = "--";
linestart = i + 1;
}
}
args[num_args] = 0;

execv(*args, args);
unable_to_execute();
}

int main(int argc, char **argv) {
stralloc filters = {0};
char *filterfile;
char *qqqargs[] = { "bin/qmail-qfilter-queue", 0 };

if ((filterfile = env_get("QMAILQUEUEFILTERS")))
if (control_readfile(&filters,filterfile,0) != 1)
unable_to_verify();
if (!env_put("QMAILQUEUEFILTERS=control/smtpfilters"))
unable_to_verify();

run_qmail_qfilter(&filters);
execv(*qqqargs, qqqargs);
unable_to_execute();
}

0 comments on commit 26188fb

Please sign in to comment.
You can’t perform that action at this time.