mod_access_rblのapache2.2.4用のパッチ
おかしかったらごめんなさい。
対象はApacheソースのmodules/mod_authz_host.c
--- mod_authz_host.c.orig 2007-07-07 10:12:12.000000000 +0900 +++ mod_authz_host.c 2007-07-07 11:11:08.000000000 +0900 @@ -19,6 +19,7 @@ * * Module derived from code originally written by Rob McCool * + * 'via' mods to handle RBL style dns lookup by blarson@blars.org */ #include "apr_strings.h" @@ -45,6 +46,7 @@ T_ALL, T_IP, T_HOST, + T_VIA, T_FAIL }; @@ -116,8 +118,17 @@ char msgbuf[120]; apr_status_t rv; - if (strcasecmp(from, "from")) - return "allow and deny must be followed by 'from'"; + if (!strcasecmp(from, "via")) { + if (strlen(where) > 80) + return "'via' location limited to 80 characters"; + a = (allowdeny *) apr_array_push(cmd->info ? d->allows : d->denys); + a->limited = cmd->limited; + a->type = T_VIA; + a->x.from = where; + return NULL; + } + else if (strcasecmp(from, "from")) + return "allow and deny must be followed by 'from' or 'via'"; a = (allowdeny *) apr_array_push(cmd->info ? d->allows : d->denys); a->x.from = where; @@ -199,6 +210,41 @@ } } +static int check_via(request_rec *r, const char *via_list) +{ + char hb[100]; + char *ha, *s, *sb, *sc; + +/* take the network address, convert to ascii, reverse the order of + * the numbers, tack on the rbl-style list to search, add a period + * at the end if there isn't one already, and see if it's listed */ +/* perhaps caching results would be a good idea */ + + ha = r->connection->remote_ip; + s = ha + strlen(ha); + sb = hb; + while (--s != ha) { + if (*s == '.') { + sc = s; + while (*++sc != '.' && *sc) *sb++ = *sc; + *sb++ = '.'; + } + } + sc = s; + while (*sc != '.' && *sc) *sb++ = *sc++; + *sb++ = '.'; + sc = (char *)via_list; + while (*sb++ = *sc++) ; + if (sb[-2] != '.') { + sb[-1] = '.'; + *sb = '\0'; + } + ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, 0, r, + "looking up %s\n", hb); + return gethostbyname(hb) != NULL; +} + + static int find_allowdeny(request_rec *r, apr_array_header_t *a, int method) { @@ -251,6 +297,11 @@ } break; + case T_VIA: + if (check_via(r, ap[i].x.from)) + return 1; + break; + case T_FAIL: /* do nothing? */ break;