Commit | Line | Data |
---|---|---|
f2863bc0 WD |
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 | ||
72e5645e | 11 | based-on: 3b8f8192227b14e708bf535072485e50f4362270 |
f2863bc0 WD |
12 | diff --git a/access.c b/access.c |
13 | --- a/access.c | |
14 | +++ b/access.c | |
fc557362 | 15 | @@ -210,6 +210,38 @@ static int match_address(const char *addr, const char *tok) |
f2863bc0 WD |
16 | return ret; |
17 | } | |
18 | ||
fc557362 | 19 | +static int match_hostlookup(const char *addr, const char *tok) |
f2863bc0 | 20 | +{ |
85096e5e | 21 | + struct hostent *hp = NULL; |
f2863bc0 | 22 | + unsigned int i, len; |
fc557362 | 23 | + const char *p; |
f2863bc0 | 24 | + |
fc557362 | 25 | + if ((p = strchr(tok,'/')) != NULL) |
f2863bc0 | 26 | + len = p - tok; |
fc557362 | 27 | + else |
f2863bc0 WD |
28 | + len = strlen(tok); |
29 | + | |
85096e5e | 30 | + /* Fail quietly (hp left NULL) if tok is an address, not a hostname. */ |
f2863bc0 | 31 | +#ifdef INET6 |
fc557362 | 32 | + if (strcspn(tok, ":/") != len) { |
85096e5e WD |
33 | + ; |
34 | + } else | |
f2863bc0 | 35 | +#endif |
85096e5e WD |
36 | + if (strspn(tok, ".0123456789") != len) |
37 | + hp = gethostbyname(tok); | |
f2863bc0 | 38 | + |
85096e5e | 39 | + if (!hp) |
f2863bc0 WD |
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 | + | |
fc557362 | 51 | static int access_match(const char *list, const char *addr, const char *host) |
f2863bc0 WD |
52 | { |
53 | char *tok; | |
fc557362 WD |
54 | @@ -221,7 +253,7 @@ static int access_match(const char *list, const char *addr, const char *host) |
55 | strlower(list2); | |
f2863bc0 WD |
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 | } |