changed whitelist format to be: ipaddress com.domain.subdomain This allows simpler maintence, sort +1 of the file groups all the smtpXX.gmail.com entries together so I can take a guess at a CIDR mask for them. Gmail is a bad example as their spf data gives me all I need but others are less helpfull. Notes: Mon Apr 10 11:21:59 EDT 2006 rsc I don't believe this is worthwhile. You've made the format harder for humans to deal with just so that an automated tool has an easier time. Anyone wanting to cut and paste one of the domain names now has to manually reverse it before proceeding. A better approach would be to use a trivial awk script to transform the domain names, sort, and then run the same awk script to put them back. I do see the value in having one line per entry. I applied that part. Reference: /n/sources/patch/applied/whitelist-format Date: Sun Apr 9 20:59:35 CES 2006 Signed-off-by: steve@quintile.net Reviewed-by: rsc --- /sys/src/cmd/upas/smtp/greylist.c Sun Apr 9 20:56:40 2006 +++ /sys/src/cmd/upas/smtp/greylist.c Sun Apr 9 20:56:38 2006 @@ -33,7 +33,7 @@ onwhitelist(void) { int lnlen; - char *line, *parse; + char *line, *parse, *a[2]; char input[128]; uchar ip[IPaddrlen], ipmasked[IPaddrlen]; uchar mask4[IPaddrlen], addr4[IPaddrlen]; @@ -52,16 +52,18 @@ if (wl == nil) return 1; while ((line = Brdline(wl, '\n')) != nil) { - if (line[0] == '#' || line[0] == '\n') - continue; lnlen = Blinelen(wl); line[lnlen-1] = '\0'; /* clobber newline */ + if (tokenize(line, a, sizeof(a)) < 1) + continue; + if (*a[0] == '#' || *a[0] == 0) + continue; /* default mask is /32 (v4) or /128 (v6) for bare IP */ - parse = line; - if (strchr(line, '/') == nil) { - strncpy(input, line, sizeof input - 5); - if (strchr(line, '.') != nil) + parse = a[0]; + if (strchr(parse, '/') == nil) { + strncpy(input, parse, sizeof input - 5); + if (strchr(parse, '.') != nil) strcat(input, "/32"); else strcat(input, "/128"); @@ -238,6 +240,23 @@ return 0; } +static char * +rev(char *str) +{ + int i, n; + char *a[64]; + static char buf[255]; + + *buf = 0; + n = gettokens(str, a, sizeof a, "."); + for (i = 0; i < n-1; i++){ + strcat(buf, a[n-i-1]); + strcat(buf, "."); + } + strcat(buf, a[n-i-1]); + return buf; +} + void vfysenderhostok(void) { @@ -259,9 +278,9 @@ if (fd >= 0) { seek(fd, 0, 2); /* paranoia */ if ((fqdn = csgetvalue(nil, "ip", nci->rsys, "dom", nil)) != nil) - fprint(fd, "# %s\n%s\n\n", fqdn, nci->rsys); + fprint(fd, "%-24s %s\n", nci->rsys, rev(fqdn)); else - fprint(fd, "# unknown\n%s\n\n", nci->rsys); + fprint(fd, "%s\n", nci->rsys); close(fd); } } else {