summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-20 11:05:02 -0700
committerJohn Denker <jsd@av8n.com>2012-07-20 11:05:02 -0700
commitd77d56ab050f7763f06461787cc862b6ec0095c4 (patch)
treea88976156764ecdd57b8a1a314cb5dd4551265ed /tools
parentefd833cb48f0181c20d9c85466126540fa46c859 (diff)
add some exit-code processing; require TCPREMOTEHOST
Diffstat (limited to 'tools')
-rw-r--r--tools/greylist.c39
-rw-r--r--tools/hi-q.c67
-rw-r--r--tools/hi-test.conf2
3 files changed, 78 insertions, 30 deletions
diff --git a/tools/greylist.c b/tools/greylist.c
index 1745b32..1320257 100644
--- a/tools/greylist.c
+++ b/tools/greylist.c
@@ -26,10 +26,17 @@ const int day(24*hour);
const int minimum_age(15*minute);
const int maximum_age(32*day);
const int probation(4*hour);
-const int sa_good = 0;
-const int bug_bait_grey = 1;
-// qmail_queue and spamc have similar interpretations here:
-const int sa_syserr = 71;
+
+// error exit codes, mostly as stated in qmail.c
+#define foo(name, num) const int ex_ ## name = num
+#define bar foo(good, 0) ;\
+foo(spam, 21) ;\
+foo(greylisting, 70) ;\
+foo(syserr, 71) ;\
+foo(comerr, 74) ;
+
+bar
+#undef foo
pid_t mypid;
string progname;
@@ -53,7 +60,7 @@ int prefix(const string shorter, const string longer){
}
void exeunt(const int sts){
- if (sts == sa_good) exit(sts);
+ if (sts == ex_good) exit(sts);
const char* foo = getenv("HI_Q_GROUP");
if (!foo) exit(sts);
@@ -188,7 +195,7 @@ int main(int _argc, char** _argv){
copies++;
} else {
cerr << "Unrecognized arg: " << arg << endl;
- exeunt(sa_syserr);
+ exeunt(ex_syserr);
}
}
if (scanmode) {
@@ -203,11 +210,17 @@ int whatsit::doit(){
char* ipvar = getenv("TCPREMOTEIP");
if (!ipvar) {
cerr << progname << ": TCPREMOTEIP not set???" << endl;
- exeunt(sa_syserr);
+ exeunt(ex_syserr);
}
ipbase = ipvar;
char* hostvar = getenv("TCPREMOTEHOST");
- if (hostvar) hostname = hostvar;
+ if (!hostvar) {
+ cerr << progname
+ << ": from " << ipbase
+ << " ... TCPREMOTEHOST not set???" << endl;
+ exeunt(ex_spam);
+ }
+ hostname = hostvar;
// see if our directory exists:
struct stat dirstat;
@@ -225,7 +238,7 @@ int whatsit::doit(){
<< ": mkdir failed for '"
<< dirname << "' : ";
perror(0);
- exeunt(sa_syserr);
+ exeunt(ex_syserr);
}
}
@@ -247,7 +260,7 @@ int whatsit::doit(){
}
close(fd);
update("new customer", now, now);
- exeunt(bug_bait_grey);
+ exeunt(ex_greylisting);
}
// here if stat succeeded
mod_age = now.tv_sec - ipstat.st_mtime;
@@ -255,16 +268,16 @@ int whatsit::doit(){
timeval mod_orig = {ipstat.st_mtime, 0};
if (mod_age < minimum_age) {
update("early bird", mod_orig, now);
- exeunt(bug_bait_grey);
+ exeunt(ex_greylisting);
}
if (mod_age - ac_age < minimum_age // early bird, or completely unused
&& mod_age > probation) { // did not diligently resubmit
update("disprobation", now, now);
- exeunt(bug_bait_grey);
+ exeunt(ex_greylisting);
}
if (ac_age > maximum_age) {
update("too old, starting over", now, now);
- exeunt(bug_bait_grey);
+ exeunt(ex_greylisting);
}
// if all checks are passed, must be OK:
update("returning customer", mod_orig, now);
diff --git a/tools/hi-q.c b/tools/hi-q.c
index 21724a1..f195508 100644
--- a/tools/hi-q.c
+++ b/tools/hi-q.c
@@ -27,11 +27,42 @@ using namespace std;
#include <map>
// error exit codes, mostly as stated in qmail.c
-const int ex_good = 0;
-const int ex_spam = 21;
-const int ex_grey = 70;
-const int ex_syserr = 71;
-const int ex_comerr = 74;
+#define bar \
+foo(good, 0) ;\
+foo(spam, 21) ;\
+foo(permerr, 31) ;\
+foo(greylisting, 70) ;\
+foo(syserr, 71) ;\
+foo(comerr, 74) ;
+
+#define foo(name, num) const int ex_ ## name = num
+bar
+#undef foo
+
+map<int,string> codemap;
+
+
+#define bar_sa \
+foo_sa(GOOD, 0, "ham") ;\
+foo_sa(SPAM, 1, "spam") ;\
+foo_sa(USAGE, 64, "command line usage error") ;\
+foo_sa(DATAERR, 65, "data format error") ;\
+foo_sa(NOINPUT, 66, "cannot open input") ;\
+foo_sa(NOUSER, 67, "addressee unknown") ;\
+foo_sa(NOHOST, 68, "host name unknown") ;\
+foo_sa(UNAVAILABLE, 69, "service unavailable") ;\
+foo_sa(SOFTWARE, 70, "internal software error") ;\
+foo_sa(OSERR, 71, "system error (e.g., can't fork)") ;\
+foo_sa(OSFILE, 72, "critical OS file missing") ;\
+foo_sa(CANTCREAT, 73, "can't create (user) output file") ;\
+foo_sa(IOERR, 74, "input/output error") ;\
+foo_sa(TEMPFAIL, 75, "temp failure; user is invited to retry") ;\
+foo_sa(PROTOCOL, 76, "remote error in protocol") ;\
+foo_sa(NOPERM, 77, "permission denied") ;\
+foo_sa(CONFIG, 78, "configuration error") ;\
+foo_sa(TOOBIG, 98, "message was too big to process (see --max-size)"
+
+
#define bufsize 16384
@@ -176,8 +207,11 @@ public:
int main(int argc, char** argv) {
progname = *argv;
mypid = getpid();
-// dump("TCPREMOTEIP");
-// dump("TCPREMOTEHOST");
+
+#define foo(name, num) codemap[num] = #name ;
+bar
+#undef foo
+
int verbose(0);
int kidstatus;
@@ -502,15 +536,15 @@ int main(int argc, char** argv) {
if (best_blame) {
string short_name("");
int kidno(iiofpid[argbest_blame]);
- string exword = "spam";
- int excode = ex_spam;
- if (filter[kidno].mode == grey) {
- exword = "greylisting";
- excode = ex_grey;
- }
if (WIFEXITED(best_blame)) {
+ string exword = "spam"; // default, for non-modern status codes
+ int excode = ex_spam; // default, for non-modern status codes
int sts = WEXITSTATUS(best_blame);
- if (sts == 1) {
+ if (filter[kidno].mode == grey) {
+ exword = codemap[sts];
+ excode = sts;
+ }
+ if (exword.length()) {
cerr << "hi-q says: kid[" << kidno << "]"
<< " pid " << argbest_blame
<< " i.e. '" << filter[kidno].cmd[0] << "'"
@@ -523,8 +557,9 @@ int main(int argc, char** argv) {
<< endl;
panic(ex_syserr);
} else {
- // should never get here unless exit status was nonzero
- cerr << "hi-q: should never happen" << endl;
+ // should never get here
+ // should be no accounting for blame if there was no blame
+ cerr << "hi-q: should never happen: no child to blame" << endl;
panic(ex_syserr);
}
} else if (WIFSIGNALED(best_blame)) {
diff --git a/tools/hi-test.conf b/tools/hi-test.conf
index d400373..a89640d 100644
--- a/tools/hi-test.conf
+++ b/tools/hi-test.conf
@@ -2,5 +2,5 @@
# another comment, with blank line between
black hi-test x0 -snooze 10
-black hi-test x1 -snooze 1 -exit 1 -kill
+black hi-test x1 -snooze 1 -exit 2 -kill
qq hi-test x2 -snooze 10