The patches for 3.0.9.
[rsync.git/patches.git] / daemon-forward-lookup.diff
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: 40afd365cc8ca968fd16e161d24df5b8a8a520cc
12 diff --git a/access.c b/access.c
13 --- a/access.c
14 +++ b/access.c
15 @@ -210,6 +210,42 @@ static int match_address(char *addr, char *tok)
16         return ret;
17  }
18  
19 +static int match_hostlookup(char *addr, char *tok)
20 +{
21 +       struct hostent *hp = NULL;
22 +       unsigned int i, len;
23 +       char *p;
24 +
25 +       if ((p = strchr(tok,'/')) != NULL) {
26 +               *p = '\0';
27 +               len = p - tok;
28 +       } else
29 +               len = strlen(tok);
30 +
31 +       /* Fail quietly (hp left NULL) if tok is an address, not a hostname. */
32 +#ifdef INET6
33 +       if (strchr(tok, ':') != NULL) {
34 +               ;
35 +       } else
36 +#endif
37 +       if (strspn(tok, ".0123456789") != len)
38 +               hp = gethostbyname(tok);
39 +
40 +       if (p)
41 +               *p = '/';
42 +
43 +       if (!hp)
44 +               return 0;
45 +
46 +       for (i = 0; hp->h_addr_list[i] != NULL; i++) {
47 +               tok = inet_ntoa(*(struct in_addr*)(hp->h_addr_list[i]));
48 +               if (match_address(addr, tok))
49 +                       return 1;
50 +       }
51 +
52 +       return 0;
53 +}
54 +
55  static int access_match(char *list, char *addr, char *host)
56  {
57         char *tok;
58 @@ -223,7 +259,7 @@ static int access_match(char *list, char *addr, char *host)
59                 strlower(host);
60  
61         for (tok = strtok(list2, " ,\t"); tok; tok = strtok(NULL, " ,\t")) {
62 -               if (match_hostname(host, tok) || match_address(addr, tok)) {
63 +               if (match_hostname(host, tok) || match_address(addr, tok) || match_hostlookup(addr, tok)) {
64                         free(list2);
65                         return 1;
66                 }