--- grey.c.original Thu Jul 5 15:56:26 2007 +++ grey.c Tue Jul 10 17:54:30 2007 @@ -304,6 +304,30 @@ return(buf); } + +char * +dequotefromlower(const char *addr) +{ + static char buf[MAX_MAIL]; + char *cp; + + if (*addr == '<'); + addr++; + (void) strlcpy(buf, addr, sizeof(buf)); + cp = strrchr(buf, '>'); + if (cp != NULL && cp[1] == '\0') + *cp = '\0'; + cp = buf; + while (*cp != '\0') { + *cp = tolower(*cp); + cp++; + } + return(buf); +} + + + + void readsuffixlists(void) { @@ -630,29 +654,38 @@ } int -trapcheck(DB *db, char *to) +trapcheck(DB *db, char *to, char *from) { - int i, j, smatch = 0; + int i, j, k, smatch = 0, tmatch = 0; DBT dbk, dbd; struct mail_addr *m; - char * trap; - size_t s; + char * strap; + char * ttrap; + size_t s, t; - trap = dequotetolower(to); + strap = dequotetolower(to); + ttrap = dequotefromlower(from); + + syslog_r(LOG_DEBUG, &sdata, "to:%s | from:%s", strap, ttrap); + if (!SLIST_EMPTY(&match_suffix)) { - s = strlen(trap); + s = strlen(strap); + t = strlen(ttrap); SLIST_FOREACH(m, &match_suffix, entry) { j = s - strlen(m->addr); - if ((j >= 0) && (strcasecmp(trap+j, m->addr) == 0)) + k = t - strlen(m->addr); + if ((j >= 0) && (strcasecmp(strap+j, m->addr) == 0)) smatch = 1; - } - if (!smatch) - /* no suffixes match, so trap it */ + if ((k >= 0) && (strcasecmp(ttrap+k, m->addr) == 0)) + tmatch = 1; + + if ((!smatch) || (tmatch)) + /* no to suffixes match, or a from suffix does, so trap it */ return (0); } memset(&dbk, 0, sizeof(dbk)); - dbk.size = strlen(trap); - dbk.data = trap; + dbk.size = strlen(strap); + dbk.data = strap; memset(&dbd, 0, sizeof(dbd)); i = db->get(db, &dbk, &dbd, 0); if (i == -1) @@ -780,7 +813,8 @@ return(-1); if (asprintf(&key, "%s\n%s\n%s\n%s", ip, helo, from, to) == -1) goto bad; - r = trapcheck(db, to); + + r = trapcheck(db, to, from); switch (r) { case 1: /* do not trap */