summaryrefslogtreecommitdiff
path: root/tools/greylist.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-20 16:15:13 -0700
committerJohn Denker <jsd@av8n.com>2012-07-29 15:32:35 -0700
commiteb342191804df42d294e1579a880c58dd213d66d (patch)
treeb5bc77f6dff816274d83ef6f98ba439b9526481d /tools/greylist.c
parent51f3d88572ae0f8eea40996db28ece9cdd0dae18 (diff)
fix up error parsing and error logging
Diffstat (limited to 'tools/greylist.c')
-rw-r--r--tools/greylist.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/tools/greylist.c b/tools/greylist.c
index 00272d8..d1ff1a4 100644
--- a/tools/greylist.c
+++ b/tools/greylist.c
@@ -51,7 +51,6 @@ void dump(const string var){
}
-
////////////////
// little utility to help with argument parsing:
//
@@ -145,10 +144,13 @@ void scan(const string p, const int copies=1){
int ac_age = now.tv_sec - mystat.st_atime;
cout << setw(10) << time_out(mod_age)
<< " " << setw(10) << time_out(ac_age);
- if (mod_age < 0) {
+ if (0) {
+
+ } else if (mod_age < 0) {
cout << " penalty";
- }
- else if (mod_age - ac_age < minimum_age // early bird, or completely unused
+ } else if (mod_age < ac_age) {
+ cout << " parole";
+ } else if (mod_age - ac_age < minimum_age // early bird, or completely unused
&& mod_age > probation) { // did not diligently resubmit
cout << " disprobation";
if (mod_age != ac_age) cout << "!";
@@ -182,7 +184,7 @@ void whatsit::update(const string msg, const timeval new_mod,
timeval pen_mod(new_mod);
if (penalty) {
pen_mod = now;
- pen_mod.tv_sec += penalty;
+ pen_mod.tv_sec += penalty;
}
timeval upd[2] = {
// beware: access illogically comes *before* modification here:
@@ -193,6 +195,8 @@ void whatsit::update(const string msg, const timeval new_mod,
}
int main(int _argc, char** _argv){
+ progname = *_argv;
+ mypid = getpid();
int argc(_argc);
char** argv(_argv);
const string dirname("/var/qmail/greylist");
@@ -206,7 +210,8 @@ int main(int _argc, char** _argv){
scanmode++;
} else if (prefix(arg, "-copy")) {
copies++;
- } else if (prefix(arg, "-penalize")) {
+ } else if (prefix(arg, "-penalize")
+ || prefix(arg, "-penalty")) {
if (!argc){
cerr << "Option '" << arg << "' requires an argument" << endl;
exeunt(ex_syserr);
@@ -228,18 +233,24 @@ int main(int _argc, char** _argv){
int whatsit::doit(const int penalty){
char* ipvar = getenv("TCPREMOTEIP");
if (!ipvar) {
- cerr << progname << ": TCPREMOTEIP not set???" << endl;
+ cerr << progname
+ << "[" << mypid << "] "
+ << " TCPREMOTEIP not set???" << endl;
+ // should never happen
+ // although you can make it happen using a weird test-harness
exeunt(ex_syserr);
}
ipbase = ipvar;
char* hostvar = getenv("TCPREMOTEHOST");
if (!hostvar) {
- cerr << progname
- << ": from " << ipbase
- << " ... TCPREMOTEHOST not set???" << endl;
+ cerr << progname
+ << "[" << mypid << "] "
+ << " from " << ipbase
+ << " ... TCPREMOTEHOST not set???" << endl;
exeunt(ex_spam);
+ } else {
+ hostname = hostvar;
}
- hostname = hostvar;
// see if our directory exists:
struct stat dirstat;
@@ -289,6 +300,10 @@ int whatsit::doit(const int penalty){
update("penalty box", mod_orig, now, penalty);
exeunt(ex_spam);
}
+ if (mod_age < ac_age){
+ update("paroled spammer", now, now, penalty);
+ exeunt(ex_greylisting);
+ }
if (mod_age < minimum_age) {
update("early bird", mod_orig, now, penalty);
exeunt(ex_greylisting);