diff --git a/ChangeLog b/ChangeLog index f8ef3f5..c0d8f9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Open Proxy Scanning Bot Module for NeoStats Changelog. - Added GPL headers and credit to BOPM authors - A few fixes in a attempt to find this socket/checklist bug - Stopped setting Glines multiple times if we find a multiple open proxies, or host is listed in OPM +- Think I finally fixed the socket/checklist bug +- Fixed a few mem leaks I believe * Version 1.0Beta1 * 31/8/2002 * Fish - Initial Release \ No newline at end of file diff --git a/opsb.c b/opsb.c index b698dad..0e6c831 100644 --- a/opsb.c +++ b/opsb.c @@ -18,7 +18,7 @@ ** USA ** ** NeoStats CVS Identification -** $Id: opsb.c,v 1.3 2002/09/04 08:52:34 fishwaldo Exp $ +** $Id: opsb.c,v 1.4 2002/09/06 04:33:28 fishwaldo Exp $ */ @@ -195,6 +195,7 @@ int __Bot_Message(char *origin, char **argv, int argc) scandata = malloc(sizeof(scaninfo)); scandata->doneban = 0; scandata->u = u; + scandata->socks = NULL; if ((u2 = finduser(argv[2])) != NULL) { /* don't scan users from my server */ if (!strcasecmp(u2->server->name, me.name)) { @@ -738,13 +739,16 @@ static int ScanNick(char **av, int ac) { scannode = list_find(opsbl, av[0], findscan); if (!scannode) scannode = list_find(opsbq, av[0], findscan); if (scannode) { +#ifdef DEBUG log("ScanNick(): Not scanning %s as we are already scanning them", av[0]); +#endif return -1; } prefmsg(u->nick, s_opsb, "%s", opsb.scanmsg); scandata = malloc(sizeof(scaninfo)); scandata->u = NULL; scandata->doneban = 0; + scandata->socks = NULL; strncpy(scandata->who, u->nick, MAXHOST); strncpy(scandata->lookup, u->hostname, MAXHOST); strncpy(scandata->server, u->server->name, MAXHOST); @@ -759,9 +763,10 @@ static int ScanNick(char **av, int ac) { scandata->ipaddr.s_addr = 0; } } - if (!startscan(scandata)) + if (!startscan(scandata)) { chanalert(s_opsb, "Warning Can't scan %s", u->nick); - + log("OBSB ScanNick(): Can't scan %s. Check logs for possible errors", u->nick); + } return 1; @@ -781,17 +786,22 @@ int startscan(scaninfo *scandata) { strcpy(segv_location, "OPSB:Startscan"); - i = checkcache(scandata); - if ((i > 0) && (!scandata->u)) { - free(scandata); - return 1; + /* only check the cache when we have IP addy */ + if (scandata->dnsstate == DO_OPM_LOOKUP && scandata->u == NULL) { + i = checkcache(scandata); + if (i > 0) { + free(scandata); + return 1; + } } - switch(scandata->dnsstate) { case GET_NICK_IP: if (list_isfull(opsbl)) { if (list_isfull(opsbq)) { chanalert(s_opsb, "Warning, Both Current and queue lists are full. Not Adding additional scans"); +#ifdef DEBUG + log("OPSB: dropped scaning of %s, as queue is full", scandata->who); +#endif if (scandata->u) prefmsg(scandata->u->nick, s_opsb, "To Busy. Try again later"); free(scandata); return 0; @@ -846,6 +856,7 @@ int startscan(scaninfo *scandata) { if (dns_lookup(buf, adns_r_a, dnsblscan, scandata->who) != 1) { log("DNS: startscan() DO_OPM_LOOKUP dns_lookup() failed"); free(scandata); + free(buf); checkqueue(); return 0; } @@ -911,6 +922,7 @@ void dnsblscan(char *data, adns_answer *a) { startscan(scandata); } else { log("DNS: dnsblscan() GETNICKIP failed-> %s", show); + chanalert(s_opsb, "Warning, Couldn't get the address for %s", scandata->who); list_delete(opsbl, scannode); lnode_destroy(scannode); free(scandata); @@ -919,6 +931,7 @@ void dnsblscan(char *data, adns_answer *a) { } else { log("DNS: dnsblscan GETNICKIP rr_info failed"); + chanalert(s_opsb, "Warning, Couldnt get the address for %s. rr_info failed", scandata->who); list_delete(opsbl, scannode); lnode_destroy(scannode); free(scandata); @@ -930,11 +943,18 @@ void dnsblscan(char *data, adns_answer *a) { if (a->nrrs > 0) { /* TODO: print out what type of open proxy it is based on IP address returned */ if (scandata->u) prefmsg(scandata->u->nick, s_opsb, "%s apears in DNS blacklist", scandata->lookup); +#ifdef DEBUG + log("Got Positive OPM lookup for %s (%s)", scandata->who, scandata->lookup); +#endif scandata->dnsstate = OPMLIST; do_ban(scandata); checkqueue(); } else if (scandata->u) prefmsg(scandata->u->nick, s_opsb, "%s does not appear in DNS black list", scandata->lookup); +#ifdef DEBUG + log("Got Negative OPM lookup for %s (%s)", scandata->who, scandata->lookup); +#endif + scandata->dnsstate = NOOPMLIST; break; default: log("Warning, Unknown Status in dnsblscan()"); diff --git a/opsb.h b/opsb.h index a2b5ab3..b1b65c9 100644 --- a/opsb.h +++ b/opsb.h @@ -4,7 +4,7 @@ ** Based from GeoStats 1.1.0 by Johnathan George net@lite.net * ** NetStats CVS Identification -** $Id: opsb.h,v 1.2 2002/09/04 08:52:34 fishwaldo Exp $ +** $Id: opsb.h,v 1.3 2002/09/06 04:33:28 fishwaldo Exp $ */ @@ -112,6 +112,7 @@ list_t *exempt; #define DOING_SCAN 0x0008 #define GOTOPENPROXY 0x0010 #define OPMLIST 0x0020 +#define NOOPMLIST 0x0040 /* this is some socklist flags */ #define CONNECTING 0x0001 diff --git a/proxy.c b/proxy.c index f3da517..290dfae 100644 --- a/proxy.c +++ b/proxy.c @@ -20,7 +20,7 @@ ** USA ** ** NeoStats CVS Identification -** $Id: proxy.c,v 1.3 2002/09/04 08:52:34 fishwaldo Exp $ +** $Id: proxy.c,v 1.4 2002/09/06 04:33:28 fishwaldo Exp $ */ @@ -65,7 +65,6 @@ proxy_types proxy_list[] = { void do_ban(scaninfo *scandata) { lnode_t *socknode; socklist *sockdata; - int doneban = 0; FILE *fp; strcpy(segv_location, "OPSB:dns_lookup"); @@ -120,6 +119,7 @@ scaninfo *find_scandata(char *sockname) { cmd = strtok(buf, " "); scannode = list_find(opsbl, cmd, findscan); + free(buf); if (scannode) return lnode_get(scannode); else @@ -146,12 +146,13 @@ void cleanlist() { savescan = 1; if (scandata->dnsstate == OPMLIST) savescan = 0; - /* if this is not valid, exit */ - if (!scandata->socks) break; + /* if this is not valid, exit (ie, the scan hasn't started yet) */ + if (scandata->socks == NULL) break; /* check for open sockets */ socknode = list_first(scandata->socks); finished = 1; while (socknode) { + sockdata = lnode_get(socknode); /* if it was a open proxy, don't save the cache */ if (sockdata->flags == OPENPROXY) savescan = 0; @@ -169,10 +170,10 @@ void cleanlist() { if (scandata->u) prefmsg(scandata->u->nick, s_opsb, "Timeout Connecting to Proxy %s on port %d", proxy_list[sockdata->type].type, proxy_list[sockdata->type].port); sock_disconnect(sockname); - free(sockdata); } + /* free the socket struct as its timed out and un-connected by now */ + } - socknode = list_next(scandata->socks, socknode); } @@ -183,8 +184,20 @@ void cleanlist() { #endif if (savescan == 1) addtocache(scandata->ipaddr.s_addr); + /* destory all the nodes in the sock list */ - list_destroy_nodes(scandata->socks); + if (scandata->socks != NULL) { + socknode = list_first(scandata->socks); + while (socknode) { + sockdata = lnode_get(socknode); +#ifdef DEBUG + log("freeing sockdata %s %d", scandata->who, sockdata->type); +#endif + free(sockdata); + socknode = list_next(scandata->socks, socknode); + } + list_destroy_nodes(scandata->socks); + } scannode2 = list_next(opsbl, scannode); list_delete(opsbl, scannode); lnode_destroy(scannode); @@ -232,6 +245,12 @@ void send_status(User *u) { case DO_OPM_LOOKUP: prefmsg(u->nick, s_opsb, "Looking up DNS blacklist"); break; + case OPMLIST: + prefmsg(u->nick, s_opsb, "Host is listed in %s", opsb.opmdomain); + break; + case NOOPMLIST: + prefmsg(u->nick, s_opsb, "Host is Not listed in %s", opsb.opmdomain); + break; default: prefmsg(u->nick, s_opsb, "Unknown State (DNS)"); } @@ -386,6 +405,7 @@ int sock5_proxy(int sock) { ); len = send(sock, buf, len, MSG_NOSIGNAL); + free(buf); return(len); @@ -445,7 +465,7 @@ int proxy_read(int socknum, char *sockname) { socknode = list_next(scandata->socks, socknode); } if (i == 0) { - log("ehh can't find socket info for proxy_read()"); + log("ehh can't find socket info %s (%d) for proxy_read()", sockname, socknum); return 1; } buf = malloc(512); @@ -534,7 +554,7 @@ int proxy_write(int socknum, char *sockname) { socknode = list_next(scandata->socks, socknode); } if (i == 0) { - log("ehhh, can't find socket for proxy_write()"); + log("ehhh, can't find socket %s %d for proxy_write()", sockname, socknum); return 1; } if (sockdata->flags == CONNECTING || sockdata->flags == SOCKCONNECTED) {