| 1 | This patch adds a forward lookup of any hostnames listed in the |
| 2 | "hosts allow" or "hosts deny" daemon config options. Based on |
| 3 | a patch by Paul Williamson. |
| 4 | |
| 5 | To use this patch, run these commands for a successful build: |
| 6 | |
| 7 | patch -p1 <patches/daemon-forward-lookup.diff |
| 8 | ./configure (optional if already run) |
| 9 | make |
| 10 | |
| 11 | based-on: 24079e988fc31af4eba56cd2701fdc5a4154980d |
| 12 | diff --git a/access.c b/access.c |
| 13 | --- a/access.c |
| 14 | +++ b/access.c |
| 15 | @@ -210,6 +210,38 @@ static int match_address(const char *addr, const char *tok) |
| 16 | return ret; |
| 17 | } |
| 18 | |
| 19 | +static int match_hostlookup(const char *addr, const char *tok) |
| 20 | +{ |
| 21 | + struct hostent *hp = NULL; |
| 22 | + unsigned int i, len; |
| 23 | + const char *p; |
| 24 | + |
| 25 | + if ((p = strchr(tok,'/')) != NULL) |
| 26 | + len = p - tok; |
| 27 | + else |
| 28 | + len = strlen(tok); |
| 29 | + |
| 30 | + /* Fail quietly (hp left NULL) if tok is an address, not a hostname. */ |
| 31 | +#ifdef INET6 |
| 32 | + if (strcspn(tok, ":/") != len) { |
| 33 | + ; |
| 34 | + } else |
| 35 | +#endif |
| 36 | + if (strspn(tok, ".0123456789") != len) |
| 37 | + hp = gethostbyname(tok); |
| 38 | + |
| 39 | + if (!hp) |
| 40 | + return 0; |
| 41 | + |
| 42 | + for (i = 0; hp->h_addr_list[i] != NULL; i++) { |
| 43 | + tok = inet_ntoa(*(struct in_addr*)(hp->h_addr_list[i])); |
| 44 | + if (match_address(addr, tok)) |
| 45 | + return 1; |
| 46 | + } |
| 47 | + |
| 48 | + return 0; |
| 49 | +} |
| 50 | + |
| 51 | static int access_match(const char *list, const char *addr, const char *host) |
| 52 | { |
| 53 | char *tok; |
| 54 | @@ -221,7 +253,7 @@ static int access_match(const char *list, const char *addr, const char *host) |
| 55 | strlower(list2); |
| 56 | |
| 57 | for (tok = strtok(list2, " ,\t"); tok; tok = strtok(NULL, " ,\t")) { |
| 58 | - if (match_hostname(host, tok) || match_address(addr, tok)) { |
| 59 | + if (match_hostname(host, tok) || match_address(addr, tok) || match_hostlookup(addr, tok)) { |
| 60 | free(list2); |
| 61 | return 1; |
| 62 | } |