From f96288efc416089567dac7bcfa674b1cd6931c97 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 15 Jul 2012 05:22:05 -0700 Subject: untested possible implementation of exeunt ... kill peers as soon as we know the msg is spam --- tools/skrewt.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'tools/skrewt.c') diff --git a/tools/skrewt.c b/tools/skrewt.c index b81f0ea..2ca32a4 100644 --- a/tools/skrewt.c +++ b/tools/skrewt.c @@ -8,6 +8,9 @@ #include /* for exit() */ #include /* for strcmp() */ #include /* toupper */ +#include + +#include /* perror */ using namespace std; @@ -30,6 +33,11 @@ void usage(const int sts){ exit(sts); } +// exit codes, compatible with spamassassin (not with qmail-queue) +const int sa_good(0); +const int sa_spam(1); +const int sa_usage(64); + ///////////////////////////////////////////////////////// // Case insensitive comparison of strings @@ -97,6 +105,25 @@ int prefix(const string shorter, const string longer){ return shorter == longer.substr(0, shorter.length()); } +void exeunt(const int sts){ + if (sts == sa_good) exit(sts); + + const char* foo = getenv("HI_Q_GROUP"); + if (!foo) exit(sts); + +// No point in signalling ourself: + sighandler_t rslt = signal(SIGUSR1, SIG_IGN); + if (rslt == SIG_ERR) { + cerr << "error setting signal" << endl; + } + int k = kill(-atoi(foo), SIGUSR1); + if (k) { + cerr << "kill failed on group " << atoi(foo) << " ... "; + perror(0); + } + exit(sts); +} + //////////////////////////////////////////////////////////// int main(int _argc, const char** _argv){ //// pid_t pid = getpid(); @@ -117,18 +144,18 @@ int main(int _argc, const char** _argv){ if (prefix(arg, "-maxsize")) { if (!argc) { cerr << "Option -maxsize requires an argument" << endl; - exit(1); + exit(sa_usage); } maxsize = atoi(*argv); argv++; argc--; } if (arg.substr(0,1) == "-") { cerr << "Unrecognized option '" << arg << "'" << endl; cerr << "For help, try: " << progname << " -help" << endl; - exit(1); + exit(sa_usage); } else { cerr << "Extraneous verbiage '" << arg << "'" << endl; cerr << "For help, try: " << progname << " -help" << endl; - exit(1); + exit(sa_usage); } } @@ -157,14 +184,14 @@ int main(int _argc, const char** _argv){ msgsize += line.length()+1; if (msgsize > maxsize) { cerr << "skrewt rejection: bigger than " << maxsize << endl; - exit(1); + exeunt(sa_spam); } header += "\n" + line; } if (header.length() == 0) { if (!gotdate) { cerr << "skrewt rejection: no date" << endl; - exit(1); // disallow mail with no date + exeunt(sa_spam); // disallow mail with no date } inheads = 0; } @@ -212,7 +239,7 @@ int main(int _argc, const char** _argv){ } else if (headword == "subject") { if (rest.find("-please-bounce-this-") != string::npos) { cerr << "skrewt rejection: by request" << endl; - exit(1); + exeunt(sa_spam); } } } @@ -223,7 +250,7 @@ int main(int _argc, const char** _argv){ msgsize += line.length()+1; if (msgsize > maxsize) { cerr << "skrewt rejection: bigger than " << maxsize << endl; - exit(1); + exeunt(sa_spam); } if (line == "--" + boundary) { inheads = 1; @@ -239,8 +266,8 @@ int main(int _argc, const char** _argv){ if (0) cerr << "textlines: " << textlines << endl; if (!textlines) { cerr << "skrewt rejection: no text" << endl; - exit(1); + exeunt(sa_spam); } cerr << "skrewt normal completion" << endl; - return 0; + exit(sa_good); } -- cgit v1.2.3