1 |
|
/* |
2 |
< |
Copyright (C) 2002-2003 Erik Fears |
3 |
< |
|
4 |
< |
This program is free software; you can redistribute it and/or |
5 |
< |
modify it under the terms of the GNU General Public License |
6 |
< |
as published by the Free Software Foundation; either version 2 |
7 |
< |
of the License, or (at your option) any later version. |
8 |
< |
|
9 |
< |
This program is distributed in the hope that it will be useful, |
10 |
< |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
< |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
< |
GNU General Public License for more details. |
13 |
< |
|
14 |
< |
You should have received a copy of the GNU General Public License |
15 |
< |
along with this program; if not, write to the Free Software |
16 |
< |
|
17 |
< |
Foundation, Inc. |
18 |
< |
59 Temple Place - Suite 330 |
19 |
< |
Boston, MA 02111-1307, USA. |
20 |
< |
|
21 |
< |
*/ |
2 |
> |
* Copyright (c) 2002-2003 Erik Fears |
3 |
> |
* Copyright (c) 2014-2015 ircd-hybrid development team |
4 |
> |
* |
5 |
> |
* This program is free software; you can redistribute it and/or modify |
6 |
> |
* it under the terms of the GNU General Public License as published by |
7 |
> |
* the Free Software Foundation; either version 2 of the License, or |
8 |
> |
* (at your option) any later version. |
9 |
> |
* |
10 |
> |
* This program is distributed in the hope that it will be useful, |
11 |
> |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
> |
* GNU General Public License for more details. |
14 |
> |
* |
15 |
> |
* You should have received a copy of the GNU General Public License |
16 |
> |
* along with this program; if not, write to the Free Software |
17 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
18 |
> |
* USA |
19 |
> |
*/ |
20 |
|
|
21 |
|
#include "setup.h" |
22 |
|
|
29 |
|
#include <arpa/inet.h> |
30 |
|
#include <time.h> |
31 |
|
#include <errno.h> |
32 |
+ |
#include <assert.h> |
33 |
|
|
34 |
|
#include "compat.h" |
35 |
|
#include "config.h" |
37 |
|
#include "list.h" |
38 |
|
#include "log.h" |
39 |
|
#include "main.h" |
41 |
– |
#include "malloc.h" |
40 |
|
#include "match.h" |
41 |
+ |
#include "memory.h" |
42 |
|
#include "scan.h" |
43 |
|
#include "irc.h" |
44 |
|
#include "stats.h" |
57 |
|
int res; |
58 |
|
struct dnsbl_scan *ds; |
59 |
|
|
61 |
– |
|
60 |
|
if (inet_pton(AF_INET, ss->ip, &in) <= 0) |
61 |
|
{ |
62 |
|
log_printf("DNSBL -> Invalid address '%s', ignoring.", ss->ip); |
73 |
|
struct BlacklistConf *bl = p->data; |
74 |
|
|
75 |
|
#ifdef WORDS_BIGENDIAN |
76 |
< |
snprintf(lookup, 128, "%d.%d.%d.%d.%s", a, b, c, d, bl->name); |
76 |
> |
snprintf(lookup, sizeof(lookup), "%d.%d.%d.%d.%s", a, b, c, d, bl->name); |
77 |
|
#else |
78 |
< |
snprintf(lookup, 128, "%d.%d.%d.%d.%s", d, c, b, a, bl->name); |
78 |
> |
snprintf(lookup, sizeof(lookup), "%d.%d.%d.%d.%s", d, c, b, a, bl->name); |
79 |
|
#endif |
80 |
|
|
81 |
|
ds = xcalloc(sizeof *ds); |
85 |
|
if (OPT_DEBUG) |
86 |
|
log_printf("DNSBL -> Passed '%s' to resolver", lookup); |
87 |
|
|
88 |
< |
res = firedns_getip(FDNS_QRY_A, lookup, (void *) ds); |
88 |
> |
res = firedns_getip(FDNS_QRY_A, lookup, ds); |
89 |
|
|
90 |
< |
if (res == -1 && fdns_errno != FDNS_ERR_FDLIMIT) |
90 |
> |
if (res == -1 && firedns_errno != FDNS_ERR_FDLIMIT) |
91 |
|
{ |
92 |
< |
log_printf("DNSBL -> Error sending dns lookup for '%s': %s", lookup, firedns_strerror(fdns_errno)); |
93 |
< |
free(ds); |
92 |
> |
log_printf("DNSBL -> Error sending dns lookup for '%s': %s", lookup, firedns_strerror(firedns_errno)); |
93 |
> |
xfree(ds); |
94 |
|
} |
95 |
|
else |
96 |
|
++ss->scans; /* Increase scan count - one for each blacklist */ |
107 |
|
{ |
108 |
|
LIST_FOREACH(p, bl->reply->head) |
109 |
|
{ |
110 |
< |
struct BlacklistReplyConf *item = p->data; |
110 |
> |
const struct BlacklistReplyConf *item = p->data; |
111 |
|
|
112 |
|
if (item->number & type) |
113 |
|
{ |
126 |
|
{ |
127 |
|
LIST_FOREACH(p, bl->reply->head) |
128 |
|
{ |
129 |
< |
struct BlacklistReplyConf *item = p->data; |
129 |
> |
const struct BlacklistReplyConf *item = p->data; |
130 |
|
|
131 |
|
if (item->number == type) |
132 |
|
{ |
147 |
|
if (ss->manual_target) |
148 |
|
irc_send("PRIVMSG %s :CHECK -> DNSBL -> %s appears in BL zone %s (%s)", |
149 |
|
ss->manual_target->name, ss->ip, bl->name, text_type); |
150 |
< |
else if (!ss->positive) |
150 |
> |
else if (ss->positive == 0) |
151 |
|
{ |
152 |
|
/* Only report it if no other scans have found positives yet. */ |
153 |
|
scan_positive(ss, (bl->kline[0] ? bl->kline : IRCItem->kline), text_type); |
167 |
|
void |
168 |
|
dnsbl_result(struct firedns_result *res) |
169 |
|
{ |
170 |
< |
struct dnsbl_scan *ds = res->info; |
170 |
> |
struct dnsbl_scan *const ds = res->info; |
171 |
|
|
172 |
|
if (OPT_DEBUG) |
173 |
|
{ |
178 |
|
(unsigned char)res->text[0], |
179 |
|
(unsigned char)res->text[1], |
180 |
|
(unsigned char)res->text[2], |
181 |
< |
(unsigned char)res->text[3], fdns_errno); |
181 |
> |
(unsigned char)res->text[3], firedns_errno); |
182 |
|
else |
183 |
|
log_printf("DNSBL -> Lookup result for %s!%s@%s (%s) %d.%d.%d.%d (error: %d)", |
184 |
|
ds->ss->irc_nick, |
188 |
|
(unsigned char)res->text[0], |
189 |
|
(unsigned char)res->text[1], |
190 |
|
(unsigned char)res->text[2], |
191 |
< |
(unsigned char)res->text[3], fdns_errno); |
191 |
> |
(unsigned char)res->text[3], firedns_errno); |
192 |
|
} |
193 |
|
|
194 |
|
/* Everything is OK */ |
195 |
< |
if (res->text[0] == '\0' && fdns_errno == FDNS_ERR_NXDOMAIN) |
195 |
> |
if (res->text[0] == '\0' && firedns_errno == FDNS_ERR_NXDOMAIN) |
196 |
|
{ |
197 |
|
if (ds->ss->manual_target) |
198 |
|
irc_send("PRIVMSG %s :CHECK -> DNSBL -> %s does not appear in BL zone %s", |
201 |
|
|
202 |
|
--ds->ss->scans; /* We are done with ss here */ |
203 |
|
scan_checkfinished(ds->ss); /* This could free ss, don't use ss after this point */ |
204 |
< |
MyFree(ds); /* No longer need our information */ |
204 |
> |
xfree(ds); /* No longer need our information */ |
205 |
|
return; |
206 |
|
} |
207 |
|
|
208 |
|
/* Either an error, or a positive lookup */ |
209 |
< |
if (fdns_errno == FDNS_ERR_NONE) |
209 |
> |
if (firedns_errno == FDNS_ERR_NONE) |
210 |
|
dnsbl_positive(ds->ss, ds->bl, (unsigned char)res->text[3]); |
211 |
|
else |
212 |
|
{ |
213 |
|
log_printf("DNSBL -> Lookup error on %s: %s", res->lookup, |
214 |
< |
firedns_strerror(fdns_errno)); |
214 |
> |
firedns_strerror(firedns_errno)); |
215 |
|
|
216 |
< |
if (fdns_errno != FDNS_ERR_TIMEOUT) |
216 |
> |
if (firedns_errno != FDNS_ERR_TIMEOUT) |
217 |
|
irc_send_channels("DNSBL -> Lookup error on %s: %s", res->lookup, |
218 |
< |
firedns_strerror(fdns_errno)); |
218 |
> |
firedns_strerror(firedns_errno)); |
219 |
|
} |
220 |
|
|
221 |
|
/* Check if ss has any remaining scans */ |
222 |
|
--ds->ss->scans; /* We are done with ss here */ |
223 |
|
scan_checkfinished(ds->ss); /* This could free ss, don't use ss after this point */ |
224 |
< |
MyFree(ds); /* Finished with dnsbl_scan too */ |
224 |
> |
xfree(ds); /* Finished with dnsbl_scan too */ |
225 |
|
} |
226 |
|
|
227 |
|
void |
236 |
|
* Send an email to report this open proxy. |
237 |
|
*/ |
238 |
|
void |
239 |
< |
dnsbl_report(struct scan_struct *ss) |
239 |
> |
dnsbl_report(const struct scan_struct *ss) |
240 |
|
{ |
241 |
|
char buf[4096], cmdbuf[512]; |
242 |
|
FILE *fp; |
243 |
|
|
244 |
< |
if (ss->ip == NULL) |
247 |
< |
return; |
244 |
> |
assert(ss->ip); |
245 |
|
|
246 |
|
if (EmptyString(OpmItem->dnsbl_to) || EmptyString(OpmItem->dnsbl_from) || EmptyString(OpmItem->sendmail)) |
247 |
|
return; |
263 |
|
if ((fp = popen(cmdbuf, "w")) == NULL) |
264 |
|
{ |
265 |
|
log_printf("DNSBL -> Failed to create pipe to '%s' for email report!", cmdbuf); |
266 |
< |
irc_send_channels("I was trying to create a pipe to'%s' to send a DNSBL " |
266 |
> |
irc_send_channels("I was trying to create a pipe to '%s' to send a DNSBL " |
267 |
|
"report, and it failed! I'll give up for now.", |
268 |
|
cmdbuf); |
269 |
|
return; |