OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
6.1 KiB

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