Lines 1-148
Link Here
|
1 |
--- rblcheck.c.orig Thu Aug 20 00:47:03 1998 |
|
|
2 |
+++ rblcheck.c Mon Jul 16 16:40:55 2001 |
3 |
@@ -79,8 +79,10 @@ |
4 |
#include <sys/types.h> |
5 |
#include <netinet/in.h> |
6 |
#include <arpa/nameser.h> |
7 |
+#include <arpa/inet.h> |
8 |
#include <resolv.h> |
9 |
#include <netdb.h> |
10 |
+#include <unistd.h> |
11 |
|
12 |
#define VERSION "1.4" |
13 |
|
14 |
@@ -203,7 +205,7 @@ |
15 |
* domain. If "txt" is non-zero, we perform a TXT record lookup. We |
16 |
* return the text returned from a TXT match, or an empty string, on |
17 |
* a successful match, or NULL on an unsuccessful match. */ |
18 |
-char * rblcheck( int a, int b, int c, int d, char * rbldomain, int txt ) |
19 |
+char * rblcheck( struct in_addr a, char * rbldomain, int txt ) |
20 |
{ |
21 |
char * domain; |
22 |
char * result = NULL; |
23 |
@@ -214,12 +216,15 @@ |
24 |
const u_char * cend; |
25 |
const u_char * rend; |
26 |
int len; |
27 |
+ u_char *p; |
28 |
+ int i, j; |
29 |
|
30 |
/* 16 characters max in a dotted-quad address, plus 1 for null */ |
31 |
domain = ( char * )malloc( 17 + strlen( rbldomain ) ); |
32 |
|
33 |
+ p = (u_char *)&a; |
34 |
/* Create a domain name, in reverse. */ |
35 |
- sprintf( domain, "%d.%d.%d.%d.%s", d, c, b, a, rbldomain ); |
36 |
+ sprintf( domain, "%d.%d.%d.%d.%s", p[3], p[2], p[1], p[0], rbldomain ); |
37 |
|
38 |
/* Make our DNS query. */ |
39 |
res_init(); |
40 |
@@ -261,8 +266,8 @@ |
41 |
cp = answer + sizeof( HEADER ); |
42 |
while( *cp != '\0' ) |
43 |
{ |
44 |
- a = *cp++; |
45 |
- while( a-- ) |
46 |
+ i = *cp++; |
47 |
+ while( i-- ) |
48 |
cp++; |
49 |
} |
50 |
|
51 |
@@ -277,8 +282,8 @@ |
52 |
cp += ( NS_INT16SZ * 2 ) + NS_INT32SZ; |
53 |
|
54 |
/* Get the length and end of the buffer. */ |
55 |
- NS_GET16( c, cp ); |
56 |
- cend = cp + c; |
57 |
+ NS_GET16( i, cp ); |
58 |
+ cend = cp + i; |
59 |
|
60 |
/* Iterate over any multiple answers we might have. In |
61 |
this context, it's unlikely, but anyway. */ |
62 |
@@ -286,10 +291,10 @@ |
63 |
rend = result + RESULT_SIZE - 1; |
64 |
while( cp < cend && rp < rend ) |
65 |
{ |
66 |
- a = *cp++; |
67 |
- if( a != 0 ) |
68 |
- for( b = a; b > 0 && cp < cend && rp < rend; |
69 |
- b-- ) |
70 |
+ i = *cp++; |
71 |
+ if( i != 0 ) |
72 |
+ for( j = i; j > 0 && cp < cend && rp < rend; |
73 |
+ j-- ) |
74 |
{ |
75 |
if( *cp == '\n' || *cp == '"' || |
76 |
*cp == '\\' ) |
77 |
@@ -308,23 +313,27 @@ |
78 |
char **argv; |
79 |
{ |
80 |
extern int optind; |
81 |
- int a, b, c, d; |
82 |
+ extern char *optarg; |
83 |
+ struct hostent *ent; |
84 |
+ struct in_addr a; |
85 |
int quiet = 0; |
86 |
int txt = 0; |
87 |
int rblfiltered = 0; |
88 |
char * response; |
89 |
struct rbl * rblsites = NULL; |
90 |
struct rbl * ptr; |
91 |
+ int fail; |
92 |
+ int c; |
93 |
|
94 |
- /* Add more sites you want in the default list of RBL-alike |
95 |
- systems here. ### An easier way to change this is needed. ### */ |
96 |
- rblsites = togglesite( "rbl.maps.vix.com", rblsites ); |
97 |
- rblsites = togglesite( "rbl.dorkslayers.com", rblsites ); |
98 |
+/* Hack to handle the easy addition of sites at compile time */ |
99 |
+#define SITE(x) rblsites = togglesite( (x), rblsites); |
100 |
+#include "rblsites.h" |
101 |
+#undef SITE |
102 |
|
103 |
progname = argv[ 0 ]; |
104 |
|
105 |
- while( ( a = getopt( argc, argv, "qtls:c?hv" ) ) != EOF ) |
106 |
- switch( a ) |
107 |
+ while( ( c = getopt( argc, argv, "qtls:c?hv" ) ) != EOF ) |
108 |
+ switch( c ) |
109 |
{ |
110 |
case 'q': |
111 |
/* Quiet */ |
112 |
@@ -372,10 +381,23 @@ |
113 |
return -1; |
114 |
} |
115 |
|
116 |
- if( sscanf( argv[ optind ], "%d.%d.%d.%d", &a, &b, &c, &d ) != 4 || |
117 |
- a < 0 || a > 255 || b < 0 || b > 255 || c < 0 || c > 255 || |
118 |
- d < 0 || d > 255 ) |
119 |
- { |
120 |
+ fail = 0; |
121 |
+ if ((ent = gethostbyname(argv[optind])) != NULL) { |
122 |
+ memcpy(&a, ent->h_addr_list[0], sizeof(a)); |
123 |
+ if (ent->h_addr_list[1]) { |
124 |
+ if (!quiet) |
125 |
+ fprintf(stderr, |
126 |
+ "%s resolved to mutiple addresses: ", |
127 |
+ argv[optind]); |
128 |
+ } |
129 |
+ if (!quiet) |
130 |
+ fprintf(stderr, "checking %s\n", inet_ntoa(a)); |
131 |
+ } else { |
132 |
+ if (!inet_aton(argv[optind], &a)) |
133 |
+ fail++; |
134 |
+ } |
135 |
+ |
136 |
+ if (fail) { |
137 |
fprintf( stderr, "%s: invalid IP address\n", progname ); |
138 |
usage(); |
139 |
return -1; |
140 |
@@ -383,7 +405,7 @@ |
141 |
|
142 |
for( ptr = rblsites; ptr != NULL; ptr = ptr->next ) |
143 |
{ |
144 |
- response = rblcheck( a, b, c, d, ptr->site, txt ); |
145 |
+ response = rblcheck( a, ptr->site, txt ); |
146 |
printf( "%s%s%s%s%s%s", !quiet && !response ? "not " : "", |
147 |
!quiet ? "RBL filtered by " : "", !quiet ? ptr->site : "", |
148 |
txt && response && strlen( response ) && !quiet ? ": " : "", |