]>
Commit | Line | Data |
---|---|---|
1 | #include <stdio.h> | |
2 | #include "proxyscan.h" | |
3 | #include "../irc/irc.h" | |
4 | #include "../lib/irc_string.h" | |
5 | #include "../core/error.h" | |
6 | #include "../glines/glines.h" | |
7 | ||
8 | void proxyscan_newnick(int hooknum, void *arg) { | |
9 | nick *np=(nick *)arg; | |
10 | cachehost *chp; | |
11 | foundproxy *fpp, *nfpp; | |
12 | extrascan *esp, *espp; | |
13 | char reason[200]; | |
14 | ||
15 | int i; | |
16 | ||
17 | /* Skip 127.* and 0.* hosts */ | |
18 | if (irc_in_addr_is_loopback(&np->p_ipaddr)) | |
19 | return; | |
20 | ||
21 | /* slug: why is this here? why isn't it with the other queuing stuff? */ | |
22 | /* we're given a list of ip/subnets and port pairs which someone else has | |
23 | seen a proxy on in the past, so we scan these very aggressively | |
24 | (even ignoring the cache) | |
25 | */ | |
26 | /* disabled as the list is hopelessly out of date */ | |
27 | if ((esp=findextrascan(np->ipnode))) { | |
28 | Error("proxyextra", ERR_ERROR, "connection from possible proxy %s", IPtostr(np->p_ipaddr)); | |
29 | for (espp=esp;espp;espp=espp->nextbynode) { | |
30 | /* we force a scan on any hosts that may be an open proxy, even if they are: | |
31 | * a) already in the queue, b) we've been running < 120 seconds */ | |
32 | queuescan(np->ipnode, espp->type, espp->port, SCLASS_NORMAL, time(NULL)); | |
33 | } | |
34 | } | |
35 | ||
36 | /* slug: this BREAKS all of P's design assumptions, do NOT REENABLE THIS UNDER ANY CIRCUMSTANCES */ | |
37 | /* ignore newnick until initial burst complete */ | |
38 | /* if (!ps_ready) | |
39 | return; | |
40 | */ | |
41 | ||
42 | /* | |
43 | * Logic for connecting hosts: | |
44 | * | |
45 | * If they're in the cache and clean, return. | |
46 | * If they're in the cache, dirty, and last scanned < 30 | |
47 | * mins ago, return (they will probably go away in a minute) | |
48 | * If they're in the cache and dirty: | |
49 | * - gline them | |
50 | * - trigger the "check" scans on the known proxies | |
51 | * - trigger normal scans as for the case below.. | |
52 | * | |
53 | * If they're not in the cache, we queue up their scans | |
54 | */ | |
55 | if ((chp=findcachehost(np->ipnode))) { | |
56 | if (!chp->proxies) | |
57 | return; | |
58 | ||
59 | if (time(NULL) < (chp->lastscan + 1800)) | |
60 | return; | |
61 | ||
62 | /* Queue up all the normal scans - on the normal queue */ | |
63 | for (i=0;i<numscans;i++) { | |
64 | /* If this port is open DON'T queue the scan - we'll start it later in the CHECK class */ | |
65 | for (fpp=chp->proxies;fpp;fpp=fpp->next) { | |
66 | if (fpp->type == thescans[i].type && fpp->port == thescans[i].port) | |
67 | break; | |
68 | ||
69 | if (!fpp) | |
70 | queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0); | |
71 | } | |
72 | } | |
73 | ||
74 | /* We want these scans to start around now, so we put them at the front of the priority queue */ | |
75 | for (fpp=chp->proxies;fpp;fpp=nfpp) { | |
76 | nfpp=fpp->next; | |
77 | queuescan(np->ipnode, fpp->type, fpp->port, SCLASS_CHECK, time(NULL)); | |
78 | freefoundproxy(fpp); | |
79 | } | |
80 | ||
81 | /* set a SHORT gline - if they really have an open proxy the gline will be re-set, with a new ID */ | |
82 | snprintf(reason, sizeof(reason), "Open Proxy, see http://www.quakenet.org/openproxies.html - ID: %d", chp->glineid); | |
83 | glinebynick(np, 600, reason, GLINE_IGNORE_TRUST, "proxyscan"); | |
84 | ||
85 | chp->lastscan=time(NULL); | |
86 | chp->proxies=NULL; | |
87 | chp->glineid=0; | |
88 | } else { | |
89 | chp=addcleanhost(time(NULL)); | |
90 | np->ipnode->exts[ps_cache_ext] = chp; | |
91 | patricia_ref_prefix(np->ipnode->prefix); | |
92 | ||
93 | /* Queue up all the normal scans - on the normal queue */ | |
94 | for (i=0;i<numscans;i++) | |
95 | queuescan(np->ipnode, thescans[i].type, thescans[i].port, SCLASS_NORMAL, 0); | |
96 | } | |
97 | } |