NetBSD Problem Report #7102
Received: (qmail 23749 invoked from network); 8 Mar 1999 04:41:32 -0000
Message-Id: <m10Jrqi-000g6VC@most.weird.com>
Date: Sun, 7 Mar 1999 23:41:04 -0500 (EST)
From: woods@most.weird.com (Greg A. Woods)
Reply-To: woods@planix.com (Greg A. Woods)
To: smail3-users@cs.athabascau.ca (Smail-3 Users Mailing List),
smail3-maintainers@smail.sbay.org (Smail-3 Maintainers Mailing List),
gnats-bugs@gnats.netbsd.org (NetBSD GNATS submissions and followups),
wietse@porcupine.org (Wietse Venema)
Subject: new, portable, version of the TCP Wrappers RBL patch
>Number: 7102
>Category: lib
>Synopsis: new, portable, version of the TCP Wrappers RBL patch
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Mar 07 20:50:00 +0000 1999
>Closed-Date: Wed May 02 01:56:07 +0000 2001
>Last-Modified: Wed May 02 01:56:07 +0000 2001
>Originator:
>Release:
>Organization:
>Environment:
>Description:
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->lib-bug-people
Responsible-Changed-By: pk
Responsible-Changed-When: Mon Mar 8 01:47:33 PST 1999
Responsible-Changed-Why:
Re-assign category: pending => lib.
(To orginator: next time, please fill in those useful fields in the PR,
like `Originator', `Organization', `Release', etc...
)
State-Changed-From-To: open->closed
State-Changed-By: itojun
State-Changed-When: Tue May 1 18:55:53 PDT 2001
State-Changed-Why:
we have this code fragment in lib/libwrap already
>Unformatted:
Somehow when creating the original version of my patch to add RBL
support to TCP Wrappers I made the mistake of doing all my testing only
on big-endian machines.
Now if only I could remember where I found the reference code where I
borrowed the original scheme of decoding the host address and see if it
still needs fixing for little-endian machines too....
This time I borrowed the scheme from NetBSD's inet_ntoa() which I expect
has been tested on about as many CPUs as any similar code ever has been
tested on. The resolver library in BIND-8 (which is where I should have
looked for example code in the first place!) uses a similar, though
perhaps not as readable, scheme.
The entire patch, corrected, is enclosed, and is also available at the
following locations:
ftp://ftp.planix.com/pub/Planix/tcp_wrappers-rbl-patch
ftp://ftp.weird.com/pub/local/tcp_wrappers-rbl-patch
where it replaces the previous, non-portable, patch.
(I'm *really* stunned that nobody else found this before I was finally
forced to use my patch on an i386 machine today! Perhaps I'm just lucky
that the address of the machine I was testing from was exactly the
byte-order inverse of an address that was listed in one of the RBLs I
use and thus the problem was instantly visible in my very first test on
an i386 platform.)
I will also be making patches available for NetBSD's inet(3) manual page
which I hope will help clarify some of the byte-order confusion
surrounding the functions it describes (at least they help my
understanding). Hopefully I've finally got a handle on this stuff!
Index: hosts_access.5
===================================================================
RCS file: /cvs/misc/tcp_wrappers/hosts_access.5,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 hosts_access.5
*** hosts_access.5 1995/08/11 17:33:12 1.1.1.1
--- hosts_access.5 1998/10/08 01:11:40
***************
*** 112,117 ****
--- 112,122 ----
built with -DPARANOID (default mode), it drops requests from such
clients even before looking at the access control tables. Build
without -DPARANOID when you want more control over such requests.
+ .IP "{RBL}.\fIdomain\fR"
+ Matches any host whose reversed address appears in the DNS under
+ \fIdomain\fR. Example domains used for blocking unsolicited
+ commercial e-mail (aka `spam\') are `.rbl.maps.vix.com\',
+ `.dul.maps.vix.com\', and `.relays.orbs.org\'.
.ne 6
.SH OPERATORS
.IP EXCEPT
Index: hosts_access.c
===================================================================
RCS file: /cvs/misc/tcp_wrappers/hosts_access.c,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 hosts_access.c
*** hosts_access.c 1997/05/24 23:07:38 1.1.1.3
--- hosts_access.c 1999/03/08 01:14:06
***************
*** 80,85 ****
--- 80,86 ----
static int server_match();
static int client_match();
static int host_match();
+ static int rbl_match();
static int string_match();
static int masked_match();
***************
*** 273,284 ****
--- 274,325 ----
} else if (STR_EQ(tok, "LOCAL")) { /* local: no dots in name */
char *name = eval_hostname(host);
return (strchr(name, '.') == 0 && HOSTNAME_KNOWN(name));
+ } else if (strncmp(tok, "{RBL}.", 6) == 0) { /* RBL lookup in domain */
+ return rbl_match(tok+6, eval_hostaddr(host));
} else if ((mask = split_at(tok, '/')) != 0) { /* net/mask */
return (masked_match(tok, mask, eval_hostaddr(host)));
} else { /* anything else */
return (string_match(tok, eval_hostaddr(host))
|| (NOT_INADDR(tok) && string_match(tok, eval_hostname(host))));
}
+ }
+
+ /* rbl_match() - match host by looking up in RBL domain */
+
+ static int rbl_match(rbl_domain, rbl_hostaddr)
+ char *rbl_domain; /* RBL domain */
+ char *rbl_hostaddr; /* hostaddr */
+ {
+ char *rbl_name;
+ unsigned long host_address;
+ char *p;
+ int ret = NO;
+ extern char *malloc();
+
+ if ((host_address = dot_quad_addr(rbl_hostaddr)) == INADDR_NONE) {
+ tcpd_warn("unable to convert %s to address", rbl_hostaddr);
+ return (NO);
+ }
+ /* construct the rbl name to look up */
+ if ((rbl_name = malloc(sizeof("255.255.255.255.") + strlen(rbl_domain) + 1)) == NULL) {
+ tcpd_jump("not enough memory to build RBL name for %s in %s", rbl_hostaddr, rbl_domain);
+ /* NOTREACHED */
+ }
+ p = (char *) (void *) &host_address;
+
+ #define UC(byte) (((int)(byte)) & 0xff)
+
+ sprintf(rbl_name, "%d.%d.%d.%d.%s", UC(p[3]), UC(p[2]), UC(p[1]), UC(p[0]), rbl_domain);
+ #undef UC
+ /* look it up */
+ if (gethostbyname(rbl_name) != NULL) {
+ /* successful lookup - they're on the RBL list */
+ /* XXX convention is the A RR returned should be 127.0.0.2 */
+ ret = YES;
+ }
+ free(rbl_name);
+
+ return ret;
}
/* string_match - match string against pattern */
--
Greg A. Woods
+1 416 218-0098 VE3TCP <gwoods@acm.org> <robohack!woods>
Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.