summaryrefslogtreecommitdiff
path: root/tools/greylist.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/greylist.c')
-rw-r--r--tools/greylist.c39
1 files changed, 26 insertions, 13 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);