Mercurial > dnsbl
comparison src/context.cpp @ 173:83fe0be032c1 stable-6-0-9
fix leak, update timestamps when receiving auto-whitelisted sender
author | carl |
---|---|
date | Thu, 06 Sep 2007 09:50:05 -0700 |
parents | bd33eaccfed8 |
children | da0c41b9f672 |
comparison
equal
deleted
inserted
replaced
172:d3189495ec68 | 173:83fe0be032c1 |
---|---|
67 char myhostname[HOST_NAME_MAX+1]; | 67 char myhostname[HOST_NAME_MAX+1]; |
68 | 68 |
69 pthread_mutex_t verifier_mutex; // protect the verifier map | 69 pthread_mutex_t verifier_mutex; // protect the verifier map |
70 verify_map verifiers; | 70 verify_map verifiers; |
71 | 71 |
72 pthread_mutex_t whitelister_mutex; // protect the | 72 pthread_mutex_t whitelister_mutex; // protect the whitelisters map |
73 whitelister_map whitelisters; | 73 whitelister_map whitelisters; |
74 | 74 |
75 string_set all_strings; // owns all the strings, only modified by the config loader thread | 75 string_set all_strings; // owns all the strings, only modified by the config loader thread |
76 const int maxlen = 1000; // used for snprintf buffers | 76 const int maxlen = 1000; // used for snprintf buffers |
77 const int maxsmtp_age = 120;// smtp verify sockets older than this are ancient | 77 const int maxsmtp_age = 120;// smtp verify sockets older than this are ancient |
445 *p = '\0'; | 445 *p = '\0'; |
446 char *who = strdup(buf); | 446 char *who = strdup(buf); |
447 time_t when = atoi(p+1); | 447 time_t when = atoi(p+1); |
448 if ((when == 0) || (when > now)) when = now; | 448 if ((when == 0) || (when > now)) when = now; |
449 autowhite_sent::iterator i = rcpts.find(who); | 449 autowhite_sent::iterator i = rcpts.find(who); |
450 if (i != rcpts.end()) { | 450 if (i == rcpts.end()) { |
451 rcpts[who] = when; | |
452 } | |
453 else { | |
451 time_t wh = (*i).second; | 454 time_t wh = (*i).second; |
452 if (when > wh) rcpts[who] = when; | 455 if (when > wh) (*i).second = when; |
453 } | 456 free(who); |
454 else { | |
455 rcpts[who] = when; | |
456 } | 457 } |
457 } | 458 } |
458 } | 459 } |
459 } | 460 } |
460 ifs.close(); | 461 ifs.close(); |
510 | 511 |
511 void WHITELISTER::sent(char *to) { | 512 void WHITELISTER::sent(char *to) { |
512 // we take ownership of the string | 513 // we take ownership of the string |
513 pthread_mutex_lock(&mutex); | 514 pthread_mutex_lock(&mutex); |
514 need = true; | 515 need = true; |
515 rcpts[to] = time(NULL); | 516 autowhite_sent::iterator i = rcpts.find(to); |
517 if (i == rcpts.end()) { | |
518 rcpts[to] = time(NULL); | |
519 } | |
520 else { | |
521 (*i).second = time(NULL); | |
522 free(to); | |
523 } | |
516 pthread_mutex_unlock(&mutex); | 524 pthread_mutex_unlock(&mutex); |
517 } | 525 } |
518 | 526 |
519 | 527 |
520 bool WHITELISTER::is_white(char *from) { | 528 bool WHITELISTER::is_white(char *from) { |
782 rcpt_rates::iterator i = rcpt_per_hour.find(user); | 790 rcpt_rates::iterator i = rcpt_per_hour.find(user); |
783 return (i == rcpt_per_hour.end()) ? default_rcpt_rate : (*i).second; | 791 return (i == rcpt_per_hour.end()) ? default_rcpt_rate : (*i).second; |
784 } | 792 } |
785 | 793 |
786 | 794 |
787 char *CONTEXT::find_from(char *from) { | 795 char *CONTEXT::find_from(char *from, bool update_white) { |
788 if (whitelister && whitelister->is_white(from)) return token_white; | 796 if (whitelister && whitelister->is_white(from)) { |
797 if (update_white) { | |
798 // update senders timestamp to extend the whitelisting period | |
799 if (debug_syslog > 1) { | |
800 char buf[maxlen]; | |
801 char msg[maxlen]; | |
802 snprintf(msg, sizeof(msg), "extend whitelist reply from <%s> in context %s", from, get_full_name(buf,maxlen)); | |
803 my_syslog(msg); | |
804 } | |
805 whitelister->sent(strdup(from)); | |
806 } | |
807 return token_white; | |
808 } | |
789 char *rc = env_from_default; | 809 char *rc = env_from_default; |
790 string_map::iterator i = env_from.find(from); | 810 string_map::iterator i = env_from.find(from); |
791 if (i != env_from.end()) rc = (*i).second; // found user@domain key | 811 if (i != env_from.end()) rc = (*i).second; // found user@domain key |
792 else { | 812 else { |
793 char *x = strchr(from, '@'); | 813 char *x = strchr(from, '@'); |