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