summaryrefslogtreecommitdiff
path: root/tools/skrewt.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-15 05:22:05 -0700
committerJohn Denker <jsd@av8n.com>2012-07-15 05:22:05 -0700
commitf96288efc416089567dac7bcfa674b1cd6931c97 (patch)
tree2ffe080000ad1306bf5d3337ce27c9ec829fa8ed /tools/skrewt.c
parent5b14bc41824ae70d33f1e7cd1486aec32b46b3e1 (diff)
untested possible implementation of exeunt ... kill peers
as soon as we know the msg is spam
Diffstat (limited to 'tools/skrewt.c')
-rw-r--r--tools/skrewt.c45
1 files changed, 36 insertions, 9 deletions
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 <stdlib.h> /* for exit() */
#include <string> /* for strcmp() */
#include <ctype.h> /* toupper */
+#include <signal.h>
+
+#include <stdio.h> /* 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);
}