Debian Codegraph @

debian/patches/11_tcpd_blacklist

raw
1 Origin: upstream, ftp://ftp.porcupine.org/pub/security/tcpd-blacklist-patch
2 Path: news.porcupine.org!news.porcupine.org!not-for-mail
3 From: Wietse Venema <wietse@((no)(spam)(please))wzv.win.tue.nl>
4 Newsgroups: comp.mail.sendmail,comp.security.unix
5 Subject: TCP Wrapper Blacklist Extension
6 Followup-To: poster
7 Date: 8 Sep 1997 18:53:13 -0400
8 Organization: Wietse's hangout while on sabattical in the USA
9 Lines: 147
10 Sender: [email protected]
11 Message-ID: <[email protected]>
12 NNTP-Posting-Host: spike.porcupine.org
13 Xref: news.porcupine.org comp.mail.sendmail:3541 comp.security.unix:7158
14
15 The patch below adds a new host pattern to the TCP Wrapper access
16 control language. Instead of a host name or address pattern, you
17 can specify an external /file/name with host name or address
18 patterns. The feature can be used recursively.
19
20 The /file/name extension makes it easy to blacklist bad sites, for
21 example, to block unwanted electronic mail when libwrap is linked
22 into sendmail. Adding hosts to a simple text file is much easier
23 than having to edit a more complex hosts.allow/deny file.
24
25 I developed this a year or so ago as a substitute for NIS netgroups.
26 At that time, I did not consider it of sufficient interest for
27 inclusion in the TCP Wrapper distribution. How times have changed.
28
29 The patch is relative to TCP Wrappers version 7.6. The main archive
30 site is ftp://ftp.win.tue.nl/pub/security/tcp_wrappers_7.6.tar.gz
31
32 Thanks to the Debian LINUX folks for expressing their interest in
33 this patch.
34
35 Wietse
36
37
38 [diff updated by Md]
39
40 diff -ruN tcp_wrappers_7.6.orig/hosts_access.5 tcp_wrappers_7.6/hosts_access.5
41 --- tcp_wrappers_7.6.orig/hosts_access.5 2004-04-10 19:28:09.000000000 +0200
42 +++ tcp_wrappers_7.6/hosts_access.5 2004-04-10 19:28:01.000000000 +0200
43 @@ -97,6 +97,13 @@
44 `[3ffe:505:2:1::]/64\' matches every address in the range
45 `3ffe:505:2:1::\' through `3ffe:505:2:1:ffff:ffff:ffff:ffff\'.
46 .IP \(bu
47 +A string that begins with a `/\' character is treated as a file
48 +name. A host name or address is matched if it matches any host name
49 +or address pattern listed in the named file. The file format is
50 +zero or more lines with zero or more host name or address patterns
51 +separated by whitespace. A file name pattern can be used anywhere
52 +a host name or address pattern can be used.
53 +.IP \(bu
54 Wildcards `*\' and `?\' can be used to match hostnames or IP addresses. This
55 method of matching cannot be used in conjunction with `net/mask\' matching,
56 hostname matching beginning with `.\' or IP address matching ending with `.\'.
57 diff -ruN tcp_wrappers_7.6.orig/hosts_access.c tcp_wrappers_7.6/hosts_access.c
58 --- tcp_wrappers_7.6.orig/hosts_access.c 2004-04-10 19:28:09.000000000 +0200
59 +++ tcp_wrappers_7.6/hosts_access.c 2004-04-10 19:27:05.000000000 +0200
60 @@ -253,6 +253,26 @@
61 }
62 }
63
64 +/* hostfile_match - look up host patterns from file */
65 +
66 +static int hostfile_match(path, host)
67 +char *path;
68 +struct hosts_info *host;
69 +{
70 + char tok[BUFSIZ];
71 + int match = NO;
72 + FILE *fp;
73 +
74 + if ((fp = fopen(path, "r")) != 0) {
75 + while (fscanf(fp, "%s", tok) == 1 && !(match = host_match(tok, host)))
76 + /* void */ ;
77 + fclose(fp);
78 + } else if (errno != ENOENT) {
79 + tcpd_warn("open %s: %m", path);
80 + }
81 + return (match);
82 +}
83 +
84 /* host_match - match host name and/or address against pattern */
85
86 static int host_match(tok, host)
87 @@ -280,6 +300,8 @@
88 tcpd_warn("netgroup support is disabled"); /* not tcpd_jump() */
89 return (NO);
90 #endif
91 + } else if (tok[0] == '/') { /* /file hack */
92 + return (hostfile_match(tok, host));
93 } else if (STR_EQ(tok, "KNOWN")) { /* check address and name */
94 char *name = eval_hostname(host);
95 return (STR_NE(eval_hostaddr(host), unknown) && HOSTNAME_KNOWN(name));
96 diff -ruN tcp_wrappers_7.6.orig/tcpdchk.c tcp_wrappers_7.6/tcpdchk.c
97 --- tcp_wrappers_7.6.orig/tcpdchk.c 2004-04-10 19:28:09.000000000 +0200
98 +++ tcp_wrappers_7.6/tcpdchk.c 2004-04-10 19:27:05.000000000 +0200
99 @@ -353,6 +353,8 @@
100 {
101 if (pat[0] == '@') {
102 tcpd_warn("%s: daemon name begins with \"@\"", pat);
103 + } else if (pat[0] == '/') {
104 + tcpd_warn("%s: daemon name begins with \"/\"", pat);
105 } else if (pat[0] == '.') {
106 tcpd_warn("%s: daemon name begins with dot", pat);
107 } else if (pat[strlen(pat) - 1] == '.') {
108 @@ -385,6 +387,8 @@
109 {
110 if (pat[0] == '@') { /* @netgroup */
111 tcpd_warn("%s: user name begins with \"@\"", pat);
112 + } else if (pat[0] == '/') {
113 + tcpd_warn("%s: user name begins with \"/\"", pat);
114 } else if (pat[0] == '.') {
115 tcpd_warn("%s: user name begins with dot", pat);
116 } else if (pat[strlen(pat) - 1] == '.') {
117 @@ -430,8 +434,13 @@
118 static int check_host(pat)
119 char *pat;
120 {
121 + char buf[BUFSIZ];
122 char *mask;
123 int addr_count = 1;
124 + FILE *fp;
125 + struct tcpd_context saved_context;
126 + char *cp;
127 + char *wsp = " \t\r\n";
128
129 if (pat[0] == '@') { /* @netgroup */
130 #ifdef NO_NETGRENT
131 @@ -450,6 +459,21 @@
132 tcpd_warn("netgroup support disabled");
133 #endif
134 #endif
135 + } else if (pat[0] == '/') { /* /path/name */
136 + if ((fp = fopen(pat, "r")) != 0) {
137 + saved_context = tcpd_context;
138 + tcpd_context.file = pat;
139 + tcpd_context.line = 0;
140 + while (fgets(buf, sizeof(buf), fp)) {
141 + tcpd_context.line++;
142 + for (cp = strtok(buf, wsp); cp; cp = strtok((char *) 0, wsp))
143 + check_host(cp);
144 + }
145 + tcpd_context = saved_context;
146 + fclose(fp);
147 + } else if (errno != ENOENT) {
148 + tcpd_warn("open %s: %m", pat);
149 + }
150 } else if (mask = split_at(pat, '/')) { /* network/netmask */
151 #ifdef INET6
152 int mask_len;