head 1.51; access; symbols milter-greylist-4-2-branch:1.51.0.8 milter-greylist-4-2-base:1.51 milter-greylist-4-2-0-base:1.51 milter-greylist-4-0-branch:1.51.0.6 milter-greylist-4-0:1.51.0.4 milter-greylist-4-0-base:1.51 milter-greylist-3-0-branch:1.51.0.2 milter-greylist-3-0-base:1.51 milter-greylist-1-6-0:1.50 milter-greylist-1-7-1:1.50 milter-greylist-1-6rc1:1.50 milter-greylist-1-6:1.50.0.2 milter-greylist-1-6-base:1.50 milter-greylist-1-5-12:1.50 milter-greylist-1-5-11:1.50 milter-greylist-1-5-10:1.50 milter-greylist-1-5-9:1.50 milter-greylist-1-5-8:1.49 milter-greylist-1-5-7:1.49 milter-greylist-1-5-6:1.48 milter-greylist-1-5-5:1.47 milter-greylist-1-5-4:1.45 milter-greylist-1-5-3:1.44 milter-greylist-1-5-2:1.44 milter-greylist-1-5-1:1.44 milter-greylist-1-4:1.44.0.2 milter-greylist-1-4-base:1.44 milter-greylist-1-3-9:1.44 milter-greylist-1-3-8:1.42 milter-greylist-1-3-7:1.42 milter-greylist-1-3-6:1.42 milter-greylist-1-3-5:1.41 milter-greylist-1-3-4:1.41 milter-greylist-1-3-3:1.40 BDB:1.40.0.2 BDB-base:1.40 before_BDB:1.40 milter-greylist-1-2-2:1.39.2.1 milter-greylist-1-3-2:1.39 milter-greylist-1-2-1:1.39 milter-greylist-1-2-0:1.39 milter-greylist-1-2:1.39.0.2 milter-greylist-1-2-base:1.39 milter-greylist-1-1-16:1.39 milter-greylist-1-1-15:1.39 milter-greylis-1-1-15:1.39 milter-greylis-1-1-16:1.39 milter-greylist-1-1-14:1.38 milter-greylist-1-1-13:1.38 milter-greylist-1-1-12:1.38 milter-greylist-1-1-11:1.37 milter-greylist-1-1-10:1.37 milter-greylist-1-10rc1:1.37 milter-greylist-1-1-9:1.37 milter-greylist-1-1-8:1.35 milter-greylist-1-1-7:1.34 milter-greylist-1-1-6:1.34 milter-greylist-1-1-5:1.33 milter-greylist-1-1-4:1.32 milter-greylist-1-1-3:1.30 milter-greylist-1-1-2:1.30 milter-greylist-1-0-2:1.28 rmilter-greylist-1-0-1:1.28 milter-greylist-1-0-1:1.28 milter-greylist-1-1-1:1.29 milter-greylist-1-0-base:1.28 milter-greylist-1-0:1.28.0.2 milter-greylist-1-0-0:1.28 milter-greylist-0-27:1.28 milter-greylist-0-26:1.28 milter-greylist-0-25:1.28 milter-greylist-0-24:1.26 milter-greylist-0-23:1.26 milter-greylist-0-22:1.24 milter-greylist-0-21:1.24 milter-greylist-0-20:1.23 milter-greylist-0-19:1.21 milter-greylist-0-18:1.20 milter-greylist-0-17:1.20 milter-greylist-0-16:1.20 milter-greylist-0-15:1.20 milter-greylist-0-14:1.20 milter-greylist-0-13:1.20 milter-greylist-0-12:1.14 milter-greylist-0-11:1.14 milter-greylist-0-10:1.12 milter-greylist-0-9:1.12 milter-greylist-0-8:1.10 milter-greylist-0-7:1.10 milter-greylist-0-6:1.9 milter-greylist-0-5:1.8 milter-greylist-0-4:1.6 milter-greylist-0-3:1.4 milter-greylist-0-2:1.3 milter-greylist-0-1:1.1.1.1 milter-greylist:1.1.1.1 ESPCI:1.1.1; locks; strict; comment @ * @; 1.51 date 2004.12.08.22.23.43; author manu; state dead; branches; next 1.50; 1.50 date 2004.10.11.20.57.42; author manu; state Exp; branches; next 1.49; 1.49 date 2004.09.13.18.41.55; author manu; state Exp; branches; next 1.48; 1.48 date 2004.08.09.20.29.08; author manu; state Exp; branches; next 1.47; 1.47 date 2004.08.02.20.17.38; author manu; state Exp; branches; next 1.46; 1.46 date 2004.08.02.12.11.48; author manu; state Exp; branches; next 1.45; 1.45 date 2004.08.01.09.27.03; author manu; state Exp; branches; next 1.44; 1.44 date 2004.06.08.14.47.47; author manu; state Exp; branches; next 1.43; 1.43 date 2004.06.07.10.03.41; author manu; state Exp; branches; next 1.42; 1.42 date 2004.05.28.10.54.35; author manu; state Exp; branches; next 1.41; 1.41 date 2004.05.26.21.50.12; author manu; state Exp; branches; next 1.40; 1.40 date 2004.05.06.13.50.55; author manu; state Exp; branches; next 1.39; 1.39 date 2004.04.13.08.31.50; author manu; state Exp; branches 1.39.2.1; next 1.38; 1.38 date 2004.04.10.07.51.10; author manu; state Exp; branches; next 1.37; 1.37 date 2004.04.02.08.57.18; author manu; state Exp; branches; next 1.36; 1.36 date 2004.04.02.06.34.47; author manu; state Exp; branches; next 1.35; 1.35 date 2004.04.01.20.36.00; author manu; state Exp; branches; next 1.34; 1.34 date 2004.04.01.09.31.34; author manu; state Exp; branches; next 1.33; 1.33 date 2004.03.31.15.31.59; author manu; state Exp; branches; next 1.32; 1.32 date 2004.03.31.10.07.17; author manu; state Exp; branches; next 1.31; 1.31 date 2004.03.31.09.49.16; author manu; state Exp; branches; next 1.30; 1.30 date 2004.03.30.15.53.53; author manu; state Exp; branches; next 1.29; 1.29 date 2004.03.28.13.59.03; author manu; state Exp; branches; next 1.28; 1.28 date 2004.03.22.23.50.01; author manu; state Exp; branches; next 1.27; 1.27 date 2004.03.22.21.56.35; author manu; state Exp; branches; next 1.26; 1.26 date 2004.03.22.07.12.38; author manu; state Exp; branches; next 1.25; 1.25 date 2004.03.22.07.01.53; author manu; state Exp; branches; next 1.24; 1.24 date 2004.03.20.07.19.03; author manu; state Exp; branches; next 1.23; 1.23 date 2004.03.19.10.16.38; author manu; state Exp; branches; next 1.22; 1.22 date 2004.03.18.22.37.21; author manu; state Exp; branches; next 1.21; 1.21 date 2004.03.18.09.55.15; author manu; state Exp; branches; next 1.20; 1.20 date 2004.03.11.14.12.48; author manu; state Exp; branches; next 1.19; 1.19 date 2004.03.10.21.11.45; author manu; state Exp; branches; next 1.18; 1.18 date 2004.03.10.20.36.29; author manu; state Exp; branches; next 1.17; 1.17 date 2004.03.10.14.24.34; author manu; state Exp; branches; next 1.16; 1.16 date 2004.03.10.14.17.13; author manu; state Exp; branches; next 1.15; 1.15 date 2004.03.09.00.12.29; author manu; state Exp; branches; next 1.14; 1.14 date 2004.03.06.20.28.44; author manu; state Exp; branches; next 1.13; 1.13 date 2004.03.06.19.06.14; author manu; state Exp; branches; next 1.12; 1.12 date 2004.03.04.09.40.12; author manu; state Exp; branches; next 1.11; 1.11 date 2004.03.04.08.38.26; author manu; state Exp; branches; next 1.10; 1.10 date 2004.03.03.16.28.30; author manu; state Exp; branches; next 1.9; 1.9 date 2004.03.02.16.26.40; author manu; state Exp; branches; next 1.8; 1.8 date 2004.03.02.10.34.37; author manu; state Exp; branches; next 1.7; 1.7 date 2004.03.02.09.15.03; author manu; state Exp; branches; next 1.6; 1.6 date 2004.03.01.14.05.41; author manu; state Exp; branches; next 1.5; 1.5 date 2004.03.01.10.18.18; author manu; state Exp; branches; next 1.4; 1.4 date 2004.02.29.22.35.09; author manu; state Exp; branches; next 1.3; 1.3 date 2004.02.29.18.07.17; author manu; state Exp; branches; next 1.2; 1.2 date 2004.02.29.15.13.30; author manu; state Exp; branches; next 1.1; 1.1 date 2004.02.21.00.01.17; author manu; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2004.02.21.00.01.17; author manu; state Exp; branches; next ; 1.39.2.1 date 2004.05.06.13.54.01; author manu; state Exp; branches; next ; desc @@ 1.51 log @New ACL framework for whitelist and greylist (Remy Card) @ text @/* $Id: except.c,v 1.50 2004/10/11 20:57:42 manu Exp $ */ /* * Copyright (c) 2004 Emmanuel Dreyfus * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Emmanuel Dreyfus * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #ifdef HAVE_SYS_CDEFS_H #include #ifdef __RCSID __RCSID("$Id: except.c,v 1.50 2004/10/11 20:57:42 manu Exp $"); #endif #endif #ifdef HAVE_OLD_QUEUE_H #include "queue.h" #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "except.h" #include "conf.h" #include "sync.h" #include "milter-greylist.h" struct exceptlist except_head; pthread_rwlock_t except_lock; static int emailcmp(char *, char *); void except_init(void) { int error; LIST_INIT(&except_head); if ((error = pthread_rwlock_init(&except_lock, NULL)) != 0) { syslog(LOG_ERR, "pthread_rwlock_init failed: %s", strerror(error)); exit(EX_OSERR); } return; } void except_add_netblock(sa, salen, cidr) /* exceptlist must be write-locked */ struct sockaddr *sa; socklen_t salen; int cidr; { ipaddr mask; struct glexcept *glexcept; char addrstr[IPADDRSTRLEN]; char maskstr[IPADDRSTRLEN]; int maxcidr, masklen; #ifdef AF_INET6 int i; #endif switch (sa->sa_family) { case AF_INET: maxcidr = 32; masklen = sizeof(mask.in4); break; #ifdef AF_INET6 case AF_INET6: maxcidr = 128; masklen = sizeof(mask.in6); break; #endif default: fprintf(stderr, "bad address family in exception list line %d\n", conf_line); exit(EX_DATAERR); } if (cidr > maxcidr || cidr < 0) { fprintf(stderr, "bad mask in exception list line %d\n", conf_line); exit(EX_DATAERR); } switch (sa->sa_family) { case AF_INET: prefix2mask4(cidr, &mask.in4); SADDR4(sa)->s_addr &= mask.in4.s_addr; break; #ifdef AF_INET6 case AF_INET6: prefix2mask6(cidr, &mask.in6); for (i = 0; i < 16; i += 4) *(uint32_t *)&SADDR6(sa)->s6_addr[i] &= *(uint32_t *)&mask.in6.s6_addr[i]; break; #endif } if ((glexcept = malloc(sizeof(*glexcept))) == NULL || (glexcept->e_addr = malloc(salen)) == NULL || (glexcept->e_mask = malloc(masklen)) == NULL) { syslog(LOG_ERR, "except malloc failed: %s", strerror(errno)); exit(EX_OSERR); } glexcept->e_type = E_NETBLOCK; glexcept->e_addrlen = salen; memcpy(glexcept->e_addr, sa, salen); memcpy(glexcept->e_mask, &mask, masklen); LIST_INSERT_HEAD(&except_head, glexcept, e_list); if (conf.c_debug) { iptostring(glexcept->e_addr, glexcept->e_addrlen, addrstr, sizeof(addrstr)); inet_ntop(glexcept->e_addr->sa_family, glexcept->e_mask, maskstr, sizeof(maskstr)); printf("load exception net %s/%s\n", addrstr, maskstr); } return; } void except_add_from(email) /* exceptlist must be write-locked */ char *email; { struct glexcept *glexcept; if ((glexcept = malloc(sizeof(*glexcept))) == NULL || (glexcept->e_from = strdup(email)) == NULL) { syslog(LOG_ERR, "except malloc failed: %s", strerror(errno)); exit(EX_OSERR); } glexcept->e_type = E_FROM; LIST_INSERT_HEAD(&except_head, glexcept, e_list); if (conf.c_debug) printf("load exception from %s\n", email); return; } void except_add_rcpt(email) /* exceptlist must be write-locked */ char *email; { struct glexcept *glexcept; if ((glexcept = malloc(sizeof(*glexcept))) == NULL || (glexcept->e_rcpt = strdup(email)) == NULL) { syslog(LOG_ERR, "except malloc failed: %s", strerror(errno)); exit(EX_OSERR); } glexcept->e_type = E_RCPT; LIST_INSERT_HEAD(&except_head, glexcept, e_list); if (conf.c_debug) printf("load exception rcpt %s\n", email); return; } void except_add_domain(domain) /* exceptlist must be write-locked */ char *domain; { struct glexcept *glexcept; if ((glexcept = malloc(sizeof(*glexcept))) == NULL || (glexcept->e_domain = strdup(domain)) == NULL) { syslog(LOG_ERR, "except malloc failed: %s", strerror(errno)); exit(EX_OSERR); } glexcept->e_type = E_DOMAIN; LIST_INSERT_HEAD(&except_head, glexcept, e_list); if (conf.c_debug) printf("load exception domain %s\n", domain); return; } #define ERRLEN 1024 void except_add_from_regex(regexstr) /* exceptlist must be write-locked */ char *regexstr; { struct glexcept *glexcept; size_t len; int error; char errstr[ERRLEN + 1]; /* * Strip leading and trailing slashes */ len = strlen(regexstr); if (len > 0) regexstr[len - 1] = '\0'; regexstr++; if ((glexcept = malloc(sizeof(*glexcept))) == NULL) { syslog(LOG_ERR, "except malloc failed: %s", strerror(errno)); exit(EX_OSERR); } if ((error = regcomp(&glexcept->e_from_re, regexstr, REG_ICASE)) != 0) { regerror(error, &glexcept->e_from_re, errstr, ERRLEN); fprintf(stderr, "bad regular expression \"%s\": %s\n", regexstr, errstr); free(glexcept); exit(EX_OSERR); } glexcept->e_type = E_FROM_RE; LIST_INSERT_HEAD(&except_head, glexcept, e_list); if (conf.c_debug) printf("load exception from regex %s\n", regexstr); return; } void except_add_rcpt_regex(regexstr) /* exceptlist must be write-locked */ char *regexstr; { struct glexcept *glexcept; size_t len; int error; char errstr[ERRLEN + 1]; /* * Strip leading and trailing slashes */ len = strlen(regexstr); if (len > 0) regexstr[len - 1] = '\0'; regexstr++; if ((glexcept = malloc(sizeof(*glexcept))) == NULL) { syslog(LOG_ERR, "except malloc failed: %s", strerror(errno)); exit(EX_OSERR); } if ((error = regcomp(&glexcept->e_rcpt_re, regexstr, REG_ICASE)) != 0) { regerror(error, &glexcept->e_rcpt_re, errstr, ERRLEN); fprintf(stderr, "bad regular expression \"%s\": %s\n", regexstr, errstr); free(glexcept); exit(EX_OSERR); } glexcept->e_type = E_RCPT_RE; LIST_INSERT_HEAD(&except_head, glexcept, e_list); if (conf.c_debug) printf("load exception rcpt regex %s\n", regexstr); return; } void except_add_domain_regex(regexstr) /* exceptlist must be write-locked */ char *regexstr; { struct glexcept *glexcept; size_t len; int error; char errstr[ERRLEN + 1]; /* * Strip leading and trailing slashes */ len = strlen(regexstr); if (len > 0) regexstr[len - 1] = '\0'; regexstr++; if ((glexcept = malloc(sizeof(*glexcept))) == NULL) { syslog(LOG_ERR, "except malloc failed: %s", strerror(errno)); exit(EX_OSERR); } if ((error = regcomp(&glexcept->e_domain_re, regexstr, REG_ICASE)) != 0) { regerror(error, &glexcept->e_domain_re, errstr, ERRLEN); fprintf(stderr, "bad regular expression \"%s\": %s\n", regexstr, errstr); free(glexcept); exit(EX_OSERR); } glexcept->e_type = E_DOMAIN_RE; LIST_INSERT_HEAD(&except_head, glexcept, e_list); if (conf.c_debug) printf("load exception domain regex %s\n", regexstr); return; } int except_rcpt_filter(rcpt, queueid) char *rcpt; char *queueid; { struct glexcept *ex; int testmode = conf.c_testmode; int retval; EXCEPT_RDLOCK; /* * Default if we do not find the recipient in the list * for testmode: the recipient is whitelisted * for normal mode: the recipient is not whitelisted. */ if (testmode) retval = EXF_RCPT; else retval = EXF_NONE; LIST_FOREACH(ex, &except_head, e_list) { /* * If we find it in the list this means: * for testmode: that it is not whitelisted * for normal mode: that it is whitelisted */ if ((ex->e_type == E_RCPT) && (emailcmp(rcpt, ex->e_rcpt) == 0)) { if (testmode) retval = EXF_NONE; else retval = EXF_RCPT; break; } if ((ex->e_type == E_RCPT_RE) && (regexec(&ex->e_rcpt_re, rcpt, 0, NULL, 0) == 0)) { if (testmode) retval = EXF_NONE; else retval = EXF_RCPT; break; } } if (testmode && (retval == EXF_RCPT)) { syslog(LOG_INFO, "%s: testmode: skipping greylist " "for recipient \"%s\"", queueid, rcpt); } EXCEPT_UNLOCK; return retval; } int except_sender_filter(sa, salen, hostname, from, queueid) struct sockaddr *sa; socklen_t salen; char *hostname; char *from; char *queueid; { struct glexcept *ex; char addrstr[IPADDRSTRLEN]; int retval; EXCEPT_RDLOCK; LIST_FOREACH(ex, &except_head, e_list) { switch (ex->e_type) { case E_RCPT: case E_RCPT_RE: break; case E_NETBLOCK: { if (ip_match(sa, ex->e_addr, ex->e_mask)) { iptostring(sa, salen, addrstr, sizeof(addrstr)); syslog(LOG_INFO, "%s: address %s is in " "exception list", queueid, addrstr); retval = EXF_ADDR; goto out; } break; } case E_DOMAIN: { /* Use emailcmp even if it's not an e-mail */ if (emailcmp(hostname, ex->e_domain) == 0) { syslog(LOG_INFO, "%s: sender DNS name %s is in " "exception list", queueid, hostname); retval = EXF_DOMAIN; goto out; } break; } case E_DOMAIN_RE: { if (regexec(&ex->e_domain_re, hostname, 0, NULL, 0) == 0) { syslog(LOG_INFO, "%s: sender DNS name %s is in " "exception list", queueid, hostname); retval = EXF_DOMAIN; goto out; } break; } case E_FROM: if (emailcmp(from, ex->e_from) == 0) { syslog(LOG_INFO, "%s: sender %s is in " "exception list", queueid, from); retval = EXF_FROM; goto out; } break; case E_FROM_RE: if (regexec(&ex->e_from_re, from, 0, NULL, 0) == 0) { syslog(LOG_INFO, "%s: sender %s is in " "exception list", queueid, from); retval = EXF_FROM; goto out; } break; default: syslog(LOG_ERR, "corrupted exception list"); exit(EX_SOFTWARE); break; } } retval = EXF_NONE; out: EXCEPT_UNLOCK; return retval; } static int emailcmp(big, little) char *big; char *little; { int i; while (big[0]) { if (tolower(big[0]) != tolower(little[0])) big++; for (i = 0; big[0] && little[i]; i++) { if (tolower(big[0]) != tolower(little[i])) break; big++; } if (little[i] == 0) return 0; } return 1; } void except_clear(void) { /* exceptlist must be write locked */ struct glexcept *glexcept; while(!LIST_EMPTY(&except_head)) { glexcept = LIST_FIRST(&except_head); LIST_REMOVE(glexcept, e_list); switch (glexcept->e_type) { case E_NETBLOCK: free(glexcept->e_addr); free(glexcept->e_mask); break; case E_FROM: free(glexcept->e_from); break; case E_RCPT: free(glexcept->e_rcpt); break; case E_DOMAIN: free(glexcept->e_domain); break; case E_FROM_RE: regfree(&glexcept->e_from_re); break; case E_RCPT_RE: regfree(&glexcept->e_rcpt_re); break; case E_DOMAIN_RE: regfree(&glexcept->e_domain_re); break; } free(glexcept); } return; } @ 1.50 log @Namespace conflicts on Tru64 Unix with IPv6 @ text @d1 1 a1 1 /* $Id: except.c,v 1.49 2004/09/13 18:41:55 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.49 2004/09/13 18:41:55 manu Exp $"); @ 1.49 log @malloc e-mail addresses, avoids truncation at 32 chars, from Hajimu Umemoto @ text @d1 1 a1 1 /* $Id: except.c,v 1.48 2004/08/09 20:29:08 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.48 2004/08/09 20:29:08 manu Exp $"); d94 1 a94 1 struct except *except; d140 3 a142 3 if ((except = malloc(sizeof(*except))) == NULL || (except->e_addr = malloc(salen)) == NULL || (except->e_mask = malloc(masklen)) == NULL) { d147 5 a151 5 except->e_type = E_NETBLOCK; except->e_addrlen = salen; memcpy(except->e_addr, sa, salen); memcpy(except->e_mask, &mask, masklen); LIST_INSERT_HEAD(&except_head, except, e_list); d154 1 a154 1 iptostring(except->e_addr, except->e_addrlen, addrstr, d156 1 a156 1 inet_ntop(except->e_addr->sa_family, except->e_mask, maskstr, d168 1 a168 1 struct except *except; d170 2 a171 2 if ((except = malloc(sizeof(*except))) == NULL || (except->e_from = strdup(email)) == NULL) { d176 2 a177 2 except->e_type = E_FROM; LIST_INSERT_HEAD(&except_head, except, e_list); d189 1 a189 1 struct except *except; d191 2 a192 2 if ((except = malloc(sizeof(*except))) == NULL || (except->e_rcpt = strdup(email)) == NULL) { d197 2 a198 2 except->e_type = E_RCPT; LIST_INSERT_HEAD(&except_head, except, e_list); d210 1 a210 1 struct except *except; d212 2 a213 2 if ((except = malloc(sizeof(*except))) == NULL || (except->e_domain = strdup(domain)) == NULL) { d218 2 a219 2 except->e_type = E_DOMAIN; LIST_INSERT_HEAD(&except_head, except, e_list); d232 1 a232 1 struct except *except; d245 1 a245 1 if ((except = malloc(sizeof(*except))) == NULL) { d250 2 a251 2 if ((error = regcomp(&except->e_from_re, regexstr, REG_ICASE)) != 0) { regerror(error, &except->e_from_re, errstr, ERRLEN); d254 1 a254 1 free(except); d258 2 a259 2 except->e_type = E_FROM_RE; LIST_INSERT_HEAD(&except_head, except, e_list); d271 1 a271 1 struct except *except; d284 1 a284 1 if ((except = malloc(sizeof(*except))) == NULL) { d289 2 a290 2 if ((error = regcomp(&except->e_rcpt_re, regexstr, REG_ICASE)) != 0) { regerror(error, &except->e_rcpt_re, errstr, ERRLEN); d293 1 a293 1 free(except); d297 2 a298 2 except->e_type = E_RCPT_RE; LIST_INSERT_HEAD(&except_head, except, e_list); d310 1 a310 1 struct except *except; d323 1 a323 1 if ((except = malloc(sizeof(*except))) == NULL) { d328 2 a329 2 if ((error = regcomp(&except->e_domain_re, regexstr, REG_ICASE)) != 0) { regerror(error, &except->e_domain_re, errstr, ERRLEN); d332 1 a332 1 free(except); d336 2 a337 2 except->e_type = E_DOMAIN_RE; LIST_INSERT_HEAD(&except_head, except, e_list); d351 1 a351 1 struct except *ex; d410 1 a410 1 struct except *ex; d513 1 a513 1 struct except *except; d516 2 a517 2 except = LIST_FIRST(&except_head); LIST_REMOVE(except, e_list); d519 1 a519 1 switch (except->e_type) { d521 2 a522 2 free(except->e_addr); free(except->e_mask); d525 1 a525 1 free(except->e_from); d528 1 a528 1 free(except->e_rcpt); d531 1 a531 1 free(except->e_domain); d534 1 a534 1 regfree(&except->e_from_re); d537 1 a537 1 regfree(&except->e_rcpt_re); d540 1 a540 1 regfree(&except->e_domain_re); d543 1 a543 1 free(except); @ 1.48 log @Use syslog instead of perror @ text @d1 1 a1 1 /* $Id: except.c,v 1.47 2004/08/02 20:17:38 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.47 2004/08/02 20:17:38 manu Exp $"); d170 2 a171 1 if ((except = malloc(sizeof(*except))) == NULL) { a176 2 strncpy(except->e_from, email, ADDRLEN); except->e_from[ADDRLEN] = '\0'; d191 2 a192 1 if ((except = malloc(sizeof(*except))) == NULL) { a197 2 strncpy(except->e_rcpt, email, ADDRLEN); except->e_rcpt[ADDRLEN] = '\0'; d212 2 a213 1 if ((except = malloc(sizeof(*except))) == NULL) { a218 2 strncpy(except->e_domain, domain, ADDRLEN); except->e_domain[ADDRLEN] = '\0'; d498 1 a498 1 for (i = 0; big[0] && little[i] && (i < ADDRLEN); i++) { d519 2 a520 1 if (except->e_type == E_NETBLOCK) { d523 11 a533 3 } if (except->e_type == E_FROM_RE) d535 2 a536 2 if (except->e_type == E_RCPT_RE) d538 2 a539 2 if (except->e_type == E_DOMAIN_RE) d541 2 a542 1 @ 1.47 log @Use uint8_t instead of u_int8_t to build on Solaris @ text @d1 1 a1 1 /* $Id: except.c,v 1.46 2004/08/02 12:11:48 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.46 2004/08/02 12:11:48 manu Exp $"); d143 1 a143 1 perror("cannot allocate memory"); d171 1 a171 1 perror("cannot allocate memory"); d193 1 a193 1 perror("cannot allocate memory"); d215 1 a215 1 perror("cannot allocate memory"); d249 1 a249 1 perror("cannot allocate memory"); d288 1 a288 1 perror("cannot allocate memory"); d327 1 a327 1 perror("cannot allocate memory"); @ 1.46 log @Changed ipaddr_t into ipaddr to fix a build problem on Solaris @ text @d1 1 a1 1 /* $Id: except.c,v 1.45 2004/08/01 09:27:03 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.45 2004/08/01 09:27:03 manu Exp $"); d134 2 a135 2 *(u_int32_t *)&SADDR6(sa)->s6_addr[i] &= *(u_int32_t *)&mask.in6.s6_addr[i]; @ 1.45 log @Full blown IPv6 support, from Hajimu Umemoto Correctly clean rc-debian.sh @ text @d1 1 a1 1 /* $Id: except.c,v 1.44 2004/06/08 14:47:47 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.44 2004/06/08 14:47:47 manu Exp $"); d93 1 a93 1 ipaddr_t mask; @ 1.44 log @Correctly check pthread function return values @ text @d1 1 a1 1 /* $Id: except.c,v 1.43 2004/06/07 10:03:41 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.43 2004/06/07 10:03:41 manu Exp $"); d88 3 a90 2 except_add_netblock(in, cidr) /* exceptlist must be write-locked */ struct in_addr *in; d93 1 a93 1 struct in_addr mask; d95 6 a100 2 char addrstr[IPADDRLEN + 1]; char maskstr[IPADDRLEN + 1]; d102 18 a119 1 if ((cidr > 32) || (cidr < 0)) { d125 14 a138 2 cidr2mask(cidr, &mask); in->s_addr &= mask.s_addr; d140 3 a142 1 if ((except = malloc(sizeof(*except))) == NULL) { d148 3 a150 2 memcpy(&except->e_addr, in, sizeof(*in)); memcpy(&except->e_mask, &mask, sizeof(mask)); d153 7 a159 6 if (conf.c_debug) printf("load exception net %s/%s\n", (char *)inet_ntop(AF_INET, &except->e_addr, addrstr, IPADDRLEN), (char *)inet_ntop(AF_INET, &except->e_mask, maskstr, IPADDRLEN)); d406 3 a408 2 except_sender_filter(in, hostname, from, queueid) struct in_addr *in; d414 1 a414 1 char addrstr[IPADDRLEN + 1]; d426 3 a428 2 if ((in->s_addr & ex->e_mask.s_addr) == ex->e_addr.s_addr) { d430 1 a430 2 "exception list", queueid, inet_ntop(AF_INET, in, addrstr, IPADDRLEN)); d521 5 @ 1.43 log @Domain regex were not freed on config file reloads @ text @d1 1 a1 1 /* $Id: except.c,v 1.42 2004/05/28 10:54:35 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.42 2004/05/28 10:54:35 manu Exp $"); d75 1 d78 5 a82 1 pthread_rwlock_init(&except_lock, NULL); @ 1.42 log @Case-insensitive regluar expression matching @ text @d1 1 a1 1 /* $Id: except.c,v 1.41 2004/05/26 21:50:12 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.41 2004/05/26 21:50:12 manu Exp $"); d483 3 @ 1.41 log @DNS support in greylist.conf through the domain keyword @ text @d1 1 a1 1 /* $Id: except.c,v 1.40 2004/05/06 13:50:55 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.40 2004/05/06 13:50:55 manu Exp $"); d210 1 a210 1 if ((error = regcomp(&except->e_from_re, regexstr, 0)) != 0) { d249 1 a249 1 if ((error = regcomp(&except->e_rcpt_re, regexstr, 0)) != 0) { d288 1 a288 1 if ((error = regcomp(&except->e_domain_re, regexstr, 0)) != 0) { @ 1.40 log @Ignore pthread_*_init return values as they are broken on some libpthread. The test were wrong to support those libs, and this prevented NetBSD 2.0 libpthread to work @ text @d1 1 a1 1 /* $Id: except.c,v 1.39 2004/04/13 08:31:50 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.39 2004/04/13 08:31:50 manu Exp $"); d165 22 d250 1 a250 1 regerror(error, &except->e_from_re, errstr, ERRLEN); d266 39 d363 1 a363 1 except_sender_filter(in, from, queueid) d365 1 d388 22 @ 1.39 log @Build problem on FreeBSD @ text @d1 1 a1 1 /* $Id: except.c,v 1.38 2004/04/10 07:51:10 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.38 2004/04/10 07:51:10 manu Exp $"); d73 1 a73 1 int a74 1 int error; d77 1 a77 2 if ((error = pthread_rwlock_init(&except_lock, NULL)) == 0) return error; d79 1 a79 1 return 0; @ 1.39.2.1 log @pull-up bugfix to run on NetBSD-2.0: ignore pthread_*_init return values as the tests were broken to support broken libtphread @ text @d1 1 a1 1 /* $Id: except.c,v 1.39 2004/04/13 08:31:50 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.39 2004/04/13 08:31:50 manu Exp $"); d73 1 a73 1 void d75 1 d78 2 a79 1 pthread_rwlock_init(&except_lock, NULL); d81 1 a81 1 return; @ 1.38 log @Bump to 1.1.12 Bugfix from Graham : In version 1.11.1, if you try to set a "rcpt" that has a regular expression (such as by uncommenting the example one in the config file), it terminates the next time it receives a message with the error: "corrupted exception list" @ text @d1 1 a1 1 /* $Id: except.c,v 1.37 2004/04/02 08:57:18 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.37 2004/04/02 08:57:18 manu Exp $"); a53 1 #include d56 1 d61 1 @ 1.37 log @Fix build troubles by removing any reference to in_addr_t @ text @d1 1 a1 1 /* $Id: except.c,v 1.36 2004/04/02 06:34:47 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.36 2004/04/02 06:34:47 manu Exp $"); d317 1 @ 1.36 log @Build problems on some Linux systems @ text @d1 1 a1 1 /* $Id: except.c,v 1.35 2004/04/01 20:36:00 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.35 2004/04/01 20:36:00 manu Exp $"); d88 1 a88 1 in_addr_t mask; d100 1 a100 1 in->s_addr &= mask; @ 1.35 log @Use regex for from and rcpt config lines @ text @d1 1 a1 1 /* $Id: except.c,v 1.34 2004/04/01 09:31:34 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.34 2004/04/01 09:31:34 manu Exp $"); d191 1 a191 1 fprintf(stderr, "bad regular expression \"s\": %s\n", d230 1 a230 1 fprintf(stderr, "bad regular expression \"s\": %s\n", @ 1.34 log @Reorder tests to minimize DNS lookups with SPF @ text @d1 1 a1 1 /* $Id: except.c,v 1.33 2004/03/31 15:31:59 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.33 2004/03/31 15:31:59 manu Exp $"); d54 1 d166 80 a268 3 if (ex->e_type != E_RCPT) continue; d274 11 a284 1 if (emailcmp(rcpt, ex->e_rcpt) == 0) { d340 9 d393 7 @ 1.33 log @Attempt to fix a warning on Solaris @ text @d1 1 a1 1 /* $Id: except.c,v 1.32 2004/03/31 10:07:17 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.32 2004/03/31 10:07:17 manu Exp $"); d166 1 a166 3 except_filter(in, from, rcpt, queueid) struct in_addr *in; char *from; a170 1 char addrstr[IPADDRLEN + 1]; d176 1 d178 3 a180 2 * Testmode: check if the recipient is in the exception list. * If not, then avoid grey listing. d182 4 a185 2 if (testmode) { int found = 0; d187 15 a201 8 LIST_FOREACH(ex, &except_head, e_list) { if (ex->e_type != E_RCPT) continue; if (emailcmp(rcpt, ex->e_rcpt) == 0) { found = 1; break; } d203 1 d205 3 a207 6 if (!found) { syslog(LOG_INFO, "%s: testmode: skipping greylist " "for recipient \"%s\"", queueid, rcpt); retval = EXF_RCPT; goto out; } d210 16 d228 3 a247 12 goto out; } break; case E_RCPT: if (testmode != 0) break; if (emailcmp(rcpt, ex->e_rcpt) == 0) { syslog(LOG_INFO, "%s: recipient %s is in " "exception list", queueid, rcpt); retval = EXF_RCPT; @ 1.32 log @Added an option for subnet mask @ text @d1 1 a1 1 /* $Id: except.c,v 1.31 2004/03/31 09:49:16 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.31 2004/03/31 09:49:16 manu Exp $"); d87 1 a87 1 struct in_addr mask; d99 1 a99 1 in->s_addr &= mask.s_addr; @ 1.31 log @Add flag equivalents to the config file @ text @d1 1 a1 1 /* $Id: except.c,v 1.30 2004/03/30 15:53:53 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.30 2004/03/30 15:53:53 manu Exp $"); d98 1 a98 7 if (cidr == 0) { bzero((void *)&mask, sizeof(mask)); } else { cidr = 32 - cidr; mask = inet_makeaddr(~((1UL << cidr) - 1), 0L); } @ 1.30 log @Set the last char of a string to 0 after strncpy just in case... @ text @d1 1 a1 1 /* $Id: except.c,v 1.29 2004/03/28 13:59:03 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.29 2004/03/28 13:59:03 manu Exp $"); a65 1 int testmode = 0; d117 1 a117 1 if (debug) d143 1 a143 1 if (debug) d165 1 a165 1 if (debug) d180 1 @ 1.29 log @Fix a bug if the netmask is /0 @ text @d1 1 a1 1 /* $Id: except.c,v 1.28 2004/03/22 23:50:01 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.28 2004/03/22 23:50:01 manu Exp $"); d141 1 d163 1 @ 1.28 log @cast inet_ntop result to fit %s format in printf @ text @d1 1 a1 1 /* $Id: except.c,v 1.27 2004/03/22 21:56:35 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.27 2004/03/22 21:56:35 manu Exp $"); d99 1 a99 1 if (cidr == 0) d101 1 a101 1 else d103 2 a104 1 mask = inet_makeaddr(~((1UL << cidr) - 1), 0L); @ 1.27 log @Include "config.h" first anywhere @ text @d1 1 a1 1 /* $Id: except.c,v 1.26 2004/03/22 07:12:38 manu Exp $ */ d37 1 a37 1 __RCSID("$Id: except.c,v 1.26 2004/03/22 07:12:38 manu Exp $"); d119 4 a122 2 inet_ntop(AF_INET, &except->e_addr, addrstr, IPADDRLEN), inet_ntop(AF_INET, &except->e_mask, maskstr, IPADDRLEN)); @ 1.26 log @Guard inclusion, some systems (older digitalUNIX) do not have it @ text @d1 1 a1 1 /* $Id: except.c,v 1.25 2004/03/22 07:01:53 manu Exp $ */ d32 2 d37 1 a37 1 __RCSID("$Id: except.c,v 1.25 2004/03/22 07:01:53 manu Exp $"); a40 1 #include "config.h" @ 1.25 log @More casts for DigitalUNIX @ text @d1 1 a1 1 /* $Id: except.c,v 1.24 2004/03/20 07:19:03 manu Exp $ */ d32 1 d35 2 a36 1 __RCSID("$Id: except.c,v 1.24 2004/03/20 07:19:03 manu Exp $"); @ 1.24 log @Print the message Id with the logs @ text @d1 1 a1 1 /* $Id: except.c,v 1.23 2004/03/19 10:16:38 manu Exp $ */ d34 1 a34 1 __RCSID("$Id: except.c,v 1.23 2004/03/19 10:16:38 manu Exp $"); d97 1 a97 1 bzero(&mask, sizeof(mask)); @ 1.23 log @Fix includes order and wrong ifdef for old queue.h @ text @d1 1 a1 1 /* $Id: except.c,v 1.22 2004/03/18 22:37:21 manu Exp $ */ d34 1 a34 1 __RCSID("$Id: except.c,v 1.22 2004/03/18 22:37:21 manu Exp $"); d165 1 a165 1 except_filter(in, from, rcpt) d169 1 d195 2 a196 2 syslog(LOG_INFO, "testmode: skipping greylist " "for recipient \"%s\"", rcpt); d207 2 a208 2 syslog(LOG_INFO, "address %s is in " "exception list", d218 2 a219 2 syslog(LOG_INFO, "sender %s is in " "exception list", from); d230 2 a231 2 syslog(LOG_INFO, "recipient %s is in " "exception list", rcpt); @ 1.22 log @Inlude config.h before using HAVE_OLD_QUEUE_H @ text @d1 1 a1 1 /* $Id: except.c,v 1.21 2004/03/18 09:55:15 manu Exp $ */ d34 8 a41 1 __RCSID("$Id: except.c,v 1.21 2004/03/18 09:55:15 manu Exp $"); a56 7 #include "config.h" #ifndef HAVE_OLD_QUEUE_H #include "queue.h" #else #include #endif @ 1.21 log @Use a modern queue.h if it is missing from the system (Linux...) @ text @d1 1 a1 1 /* $Id: except.c,v 1.20 2004/03/11 14:12:48 manu Exp $ */ d34 1 a34 1 __RCSID("$Id: except.c,v 1.20 2004/03/11 14:12:48 manu Exp $"); d51 1 @ 1.20 log @Rebuild on Linux Build again with -Werror, both on Linux and NetBSD! @ text @d1 1 a1 1 /* $Id: except.c,v 1.19 2004/03/10 21:11:45 manu Exp $ */ d34 1 a34 1 __RCSID("$Id: except.c,v 1.19 2004/03/10 21:11:45 manu Exp $"); a45 1 #include d50 6 @ 1.19 log @Renamed except.greylist as except.conf, split the cde between exception list management and config management @ text @d1 1 a1 1 /* $Id: except.c,v 1.18 2004/03/10 20:36:29 manu Exp $ */ a31 2 #define _XOPEN_SOURCE 500 d34 1 a34 1 __RCSID("$Id: except.c,v 1.18 2004/03/10 20:36:29 manu Exp $"); @ 1.18 log @Fix time diff display in debug output Get safer sync, by maintaining a per peer queue. When a peer is unreachable, its queue is not touched until it gets back again @ text @d1 1 a1 1 /* $Id: except.c,v 1.17 2004/03/10 14:24:34 manu Exp $ */ d36 1 a36 1 __RCSID("$Id: except.c,v 1.17 2004/03/10 14:24:34 manu Exp $"); d55 1 a58 1 extern int debug; a59 1 char *exceptfile = EXCEPTFILE; a61 1 struct timeval exceptfile_modified; a64 5 #define EXCEPT_WRLOCK WRLOCK(except_lock) #define EXCEPT_RDLOCK RDLOCK(except_lock) #define EXCEPT_UNLOCK UNLOCK(except_lock) a76 21 except_load(void) /* exceptlist must be write-locked */ { FILE *stream; if ((stream = fopen(exceptfile, "r")) == NULL) { fprintf(stderr, "cannot open exception file %s: %s\n", exceptfile, strerror(errno)); fprintf(stderr, "continuing with no exception list\n"); return; } except_in = stream; except_parse(); fclose(stream); (void)gettimeofday(&exceptfile_modified, NULL); return; } void d88 1 a88 1 except_line); d270 1 a270 3 except_update(void) { struct stat st; struct timeval tv1, tv2, tv3; a271 6 if (stat(exceptfile, &st) != 0) { syslog(LOG_DEBUG, "exception file \"%s\" unavailable", exceptfile); return; } a272 11 /* * exceptfile_modified is updated in except_load() */ if (st.st_mtime < exceptfile_modified.tv_sec) return; syslog(LOG_INFO, "reloading \"%s\"", exceptfile); if (debug) (void)gettimeofday(&tv1, NULL); EXCEPT_WRLOCK; a276 12 } /* Nothing to do here... */ peer_clear(); except_load(); EXCEPT_UNLOCK; if (debug) { (void)gettimeofday(&tv2, NULL); timersub(&tv2, &tv1, &tv3); syslog(LOG_DEBUG, "reloaded exception file in %ld.%06lds", tv3.tv_sec, tv3.tv_usec); @ 1.17 log @Remove unused code factor locking defines @ text @d1 1 a1 1 /* $Id: except.c,v 1.16 2004/03/10 14:17:13 manu Exp $ */ d36 1 a36 1 __RCSID("$Id: except.c,v 1.16 2004/03/10 14:17:13 manu Exp $"); d55 1 d300 1 a300 1 struct timeval tv1, tv2; d333 1 d335 1 a335 1 tv2.tv_sec - tv1.tv_sec, tv2.tv_usec - tv1.tv_usec); @ 1.16 log @MX sync @ text @d1 1 a1 1 /* $Id: except.c,v 1.15 2004/03/09 00:12:29 manu Exp $ */ d36 1 a36 1 __RCSID("$Id: except.c,v 1.15 2004/03/09 00:12:29 manu Exp $"); d66 3 a68 15 #define EXCEPT_WRLOCK if (pthread_rwlock_wrlock(&except_lock) != 0) { \ syslog(LOG_ERR, "%s:%d pthread_rwlock_wrlock failed", \ __FILE__, __LINE__); \ exit(EX_SOFTWARE); \ } #define EXCEPT_RDLOCK if (pthread_rwlock_rdlock(&except_lock) != 0) { \ syslog(LOG_ERR, "%s:%d pthread_rwlock_rdlock failed", \ __FILE__, __LINE__); \ exit(EX_SOFTWARE); \ } #define EXCEPT_UNLOCK if (pthread_rwlock_unlock(&except_lock) != 0) { \ syslog(LOG_ERR, "%s:%d pthread_rwlock_unlock failed", \ __FILE__, __LINE__); \ exit(EX_SOFTWARE); \ } @ 1.15 log @Don't forget to free memory when voiding the except queue @ text @d1 1 a1 1 /* $Id: except.c,v 1.14 2004/03/06 20:28:44 manu Exp $ */ d36 1 a36 1 __RCSID("$Id: except.c,v 1.14 2004/03/06 20:28:44 manu Exp $"); d337 2 @ 1.14 log @Remove useless \n in syslog calls @ text @d1 1 a1 1 /* $Id: except.c,v 1.13 2004/03/06 19:06:14 manu Exp $ */ d36 1 a36 1 __RCSID("$Id: except.c,v 1.13 2004/03/06 19:06:14 manu Exp $"); d312 1 d331 5 a335 2 while(!LIST_EMPTY(&except_head)) LIST_REMOVE(LIST_FIRST(&except_head), e_list); @ 1.13 log @RCSIDs @ text @d1 1 a1 1 /* $Id: except.c,v 1.12 2004/03/04 09:40:12 manu Exp $ */ d36 1 a36 1 __RCSID("$Id$"); d67 1 a67 1 syslog(LOG_ERR, "%s:%d pthread_rwlock_wrlock failed\n", \ d72 1 a72 1 syslog(LOG_ERR, "%s:%d pthread_rwlock_rdlock failed\n", \ d77 1 a77 1 syslog(LOG_ERR, "%s:%d pthread_rwlock_unlock failed\n", \ d230 1 a230 1 "for recipient \"%s\"\n", rcpt); d242 1 a242 1 "exception list\n", d253 1 a253 1 "exception list\n", from); d265 1 a265 1 "exception list\n", rcpt); d272 1 a272 1 syslog(LOG_ERR, "corrupted exception list\n"); d325 1 a325 1 syslog(LOG_INFO, "reloading \"%s\"\n", exceptfile); d338 1 a338 1 syslog(LOG_DEBUG, "reloaded exception file in %ld.%06lds\n", @ 1.12 log @Auto-reload exception file when it is modified @ text @d1 1 a1 1 /* $Id: except.c,v 1.11 2004/03/04 08:38:26 manu Exp $ */ d33 5 @ 1.11 log @Show the reason why the message was not delayed in the X-Greylist header (sender IP whitelisted or whatever) @ text @d1 1 a1 1 /* $Id: except.c,v 1.10 2004/03/03 16:28:30 manu Exp $ */ d32 2 d41 1 d45 1 d56 2 d61 17 d80 2 d83 3 d90 1 a90 1 except_load(void) d105 2 d111 1 a111 1 except_add_netblock(in, cidr) d153 1 a153 1 except_add_from(email) d174 1 a174 1 except_add_rcpt(email) d202 3 d226 2 a227 1 return EXF_RCPT; d239 2 a240 1 return EXF_ADDR; d249 2 a250 1 return EXF_FROM; d261 2 a262 1 return EXF_RCPT; d272 5 a276 1 return EXF_NONE; d301 37 @ 1.10 log @Use inet_ntop instead of inet_ntoa @ text @d1 1 a1 1 /* $Id: except.c,v 1.9 2004/03/02 16:26:40 manu Exp $ */ d193 1 a193 1 return 1; d205 1 a205 1 return 1; d214 1 a214 1 return 1; d225 1 a225 1 return 1; d235 1 a235 1 return 0; @ 1.9 log @Build on Linux Move from inet_aton to inet_pton Bump to 0.6 @ text @d1 1 a1 1 /* $Id: except.c,v 1.8 2004/03/02 10:34:37 manu Exp $ */ d87 2 d114 4 a117 9 if (debug) { /* * inet_ntoa result is a static char[], so we cannot use * inet_ntoa two times in the same function call, else we * get the same result twice. */ printf("load exception net %s", inet_ntoa(except->e_addr)); printf("/%s\n", inet_ntoa(except->e_mask)); } d171 1 d203 2 a204 1 "exception list\n", inet_ntoa(*in)); @ 1.8 log @Bugfix in emailcmp @ text @d1 1 a1 1 /* $Id: except.c,v 1.7 2004/03/02 09:15:03 manu Exp $ */ d37 1 d46 1 @ 1.7 log @Imporve the way we search for an e-mail address in a bigger string @ text @d1 1 a1 1 /* $Id: except.c,v 1.6 2004/03/01 14:05:41 manu Exp $ */ d248 1 a248 1 for (i = 0; big[i] && little[i] && (i < ADDRLEN); i++) { @ 1.6 log @When comparing e-mailaddresses, strip leading unprintable chars and an eventual bracket: " " matches "toto@@foo.com" @ text @d1 1 a1 1 /* $Id: except.c,v 1.5 2004/03/01 10:18:18 manu Exp $ */ d242 1 a242 1 int i, j; d244 3 a246 7 /* * An e-mail address starts with [A-Za-z0-9] * Strip any leading garbage, including brackets. * eg: " " -> "foo@@xample.com>" */ for (j = 0; (j < ADDRLEN) && big[0] && !isalnum(big[0]); j++) big++; d248 9 a256 10 /* * Then compare it with the smaller string. * Comparison stops as soon as the end of * a string is reached. This avoids problems * with trailing chars, including brackets. * eg: "foo@@example.com> " matches "foo@@example.com" */ for (i = 0; (i < ADDRLEN - j) && big[i] && little[i]; i++) if (tolower(big[i]) != tolower(little[i])) return 1; d258 1 a258 1 return 0; @ 1.5 log @Bug fix in exception list display at load time @ text @d1 1 a1 1 /* $Id: except.c,v 1.4 2004/02/29 22:35:09 manu Exp $ */ d238 3 a240 3 emailcmp(e1, e2) char *e1; char *e2; d242 1 a242 1 int i; d244 17 a260 2 for (i = 0; (i < ADDRLEN) && e1[i] && e2[i]; i++) if (tolower(e1[i]) != tolower(e2[i])) @ 1.4 log @Added test mode (option -T). It reverses the meaning of rcpt lines in greylist.except so that only the addresses listed suffer grey listing. Changed "to" lines in greylist.except into "rcpt", for the sake of consistency. @ text @d1 1 a1 1 /* $Id: except.c,v 1.3 2004/02/29 18:07:17 manu Exp $ */ d110 9 a118 3 if (debug) printf("load exception net %s/%s\n", inet_ntoa(except->e_addr), inet_ntoa(except->e_mask)); @ 1.3 log @Allow grey list exception based on sender and recipient addresses @ text @d1 1 a1 1 /* $Id: except.c,v 1.2 2004/02/29 15:13:30 manu Exp $ */ d47 1 d166 24 d212 3 @ 1.2 log @Introduce a lex/yacc based parser for the exception file. @ text @d1 1 a1 1 /* $Id: except.c,v 1.1.1.1 2004/02/21 00:01:17 manu Exp $ */ d34 1 d50 2 d78 1 a78 1 except_add(in, cidr) d104 1 d109 16 a124 3 if (debug) { printf("load exception %s", inet_ntoa(except->e_addr)); printf("/%s\n", inet_ntoa(except->e_mask)); d126 7 d137 20 d159 1 a159 1 except_checkaddr(in) d161 2 d167 31 a197 4 if ((in->s_addr & ex->e_mask.s_addr) == ex->e_addr.s_addr) { syslog(LOG_INFO, "address %s is in exception list\n", inet_ntoa(*in)); return 1; d200 14 @ 1.1 log @Initial revision @ text @d1 1 a1 1 /* $Id$ */ a58 9 char *format = "%15[0-9.]/%d\n"; char addr[IPADDRLEN + 1]; int cidr; struct in_addr in; struct in_addr mask; int readen; int line = 0; struct except *except; int error; d67 14 a80 53 while(feof(stream) == 0) { line++; readen = fscanf(stream, format, &addr, &cidr); switch (readen) { case 0: goto end; break; case 1: mask = inet_makeaddr(~0UL, 0L); break; case 2: if ((cidr > 32) || (cidr < 0)) { fprintf(stderr, "bad mask in exception list " "line %d\n", line); exit(EX_DATAERR); } if (cidr == 0) bzero(&mask, sizeof(mask)); else cidr = 32 - cidr; mask = inet_makeaddr(~((1UL << cidr) - 1), 0L); break; default: fprintf(stderr, "syntax error in exception list " "line %d\n", line); exit(EX_DATAERR); break; } if ((error = inet_aton(addr, &in)) != 1) { fprintf(stderr, "bad address in exception list " "line %d: %s\n", line, strerror(errno)); exit(EX_DATAERR); } in.s_addr &= mask.s_addr; if ((except = malloc(sizeof(*except))) == NULL) { perror("cannot allocate memory"); exit(EX_OSERR); } memcpy(&except->e_addr, &in, sizeof(in)); memcpy(&except->e_mask, &mask, sizeof(mask)); LIST_INSERT_HEAD(&except_head, except, e_list); if (debug) { printf("load exception %s", inet_ntoa(except->e_addr)); printf("/%s\n", inet_ntoa(except->e_mask)); } d82 4 d88 21 a108 2 end: fclose(stream); d113 1 d115 1 a115 1 except_check(in) @ 1.1.1.1 log @greylisting milter for sendmail @ text @@