win32 changes and split exempt code into seperate files

This commit is contained in:
Mark 2004-08-09 20:40:55 +00:00
parent d4a0ac2624
commit b8d5e23925
10 changed files with 123 additions and 83 deletions

View file

@ -1,5 +1,10 @@
Open Proxy Scanning Bot Module for NeoStats Changelog. Open Proxy Scanning Bot Module for NeoStats Changelog.
============================================================================== ==============================================================================
* Version 3.0 * * Mark (M)
- Changes for Win32 compatibility. (M)
- Split exempt code into seperate files. (M)
- Port to 3.0 API (M)
* Version 2.3 * 25/7/2004 * Fish (F) * Version 2.3 * 25/7/2004 * Fish (F)
- Fix a problem with "OPSB is not configured" messages - Fix a problem with "OPSB is not configured" messages
- Make sure we are using the correct config type for serval set variables - Make sure we are using the correct config type for serval set variables

View file

@ -25,6 +25,9 @@
#include "opsb.h" #include "opsb.h"
#include "exempts.h" #include "exempts.h"
/* this is the list of exempted hosts/servers */
list_t *exempt;
int opsb_cmd_exclude (CmdParams* cmdparams) int opsb_cmd_exclude (CmdParams* cmdparams)
{ {
char *buf; char *buf;
@ -134,6 +137,7 @@ void LoadExempts (void)
char datapath[BUFSIZE]; char datapath[BUFSIZE];
exemptinfo *exempts; exemptinfo *exempts;
exempt = list_create(MAX_EXEMPTS);
if (GetDir ("Exempt", &data) > 0) { if (GetDir ("Exempt", &data) > 0) {
/* try */ /* try */
for (i = 0; data[i] != NULL; i++) { for (i = 0; data[i] != NULL; i++) {
@ -168,3 +172,48 @@ void LoadExempts (void)
} }
free(data); free(data);
} }
int IsServerExempt (char *nick, char *host)
{
lnode_t *node;
exemptinfo *exempts;
node = list_first(exempt);
while (node) {
exempts = lnode_get(node);
if (exempts->server == 1) {
/* match a server */
if (match(exempts->host, host)) {
dlog (DEBUG1, "OPSB: User %s exempt. Matched host entry %s in Exemptions", nick, exempts->host);
return 1;
}
}
node = list_next(exempt, node);
}
return 0;
}
int IsUserExempt (char *nick, char *host)
{
lnode_t *node;
exemptinfo *exempts;
node = list_first(exempt);
while (node) {
exempts = lnode_get(node);
if (exempts->server == 1) {
/* match a server */
if (match(exempts->host, host)) {
dlog (DEBUG1, "OPSB: User %s exempt. Matched server entry %s in Exemptions", nick, exempts->host);
return 1;
}
}
node = list_next(exempt, node);
}
return 0;
}
int GetExemptCount (void)
{
return list_count(exempt);
}

View file

@ -13,5 +13,8 @@
void LoadExempts (void); void LoadExempts (void);
void SaveExempts (exemptinfo *exempts); void SaveExempts (exemptinfo *exempts);
int opsb_cmd_exclude (CmdParams* cmdparams); int opsb_cmd_exclude (CmdParams* cmdparams);
int IsServerExempt (char *nick, char *host);
int IsUserExempt (char *nick, char *host);
int GetExemptCount (void);
#endif /* EXEMPTS_H */ #endif /* EXEMPTS_H */

View file

@ -23,6 +23,7 @@
#ifdef WIN32 #ifdef WIN32
#include "win32modconfig.h" #include "win32modconfig.h"
#include <winsock2.h>
#else #else
#include "modconfig.h" #include "modconfig.h"
#endif #endif
@ -34,8 +35,10 @@
#endif #endif
#ifndef HAVE_INET_ATON #ifndef HAVE_INET_ATON
#ifndef WIN32
# include <netinet/in.h> # include <netinet/in.h>
#endif #endif
#endif
#include "compat.h" #include "compat.h"
#include "opm.h" #include "opm.h"

View file

@ -42,9 +42,13 @@ along with this program; if not, write to
# include <strings.h> # include <strings.h>
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#endif
#include "inet.h" #include "inet.h"
#include "opm.h" #include "opm.h"

View file

@ -2,10 +2,14 @@
#define INET_H #define INET_H
#include <sys/types.h> #include <sys/types.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#endif
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H
# include <fcntl.h> # include <fcntl.h>
#endif #endif

View file

@ -49,7 +49,9 @@
# endif # endif
#endif #endif
#ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
# include <string.h> # include <string.h>
@ -1066,8 +1068,14 @@ static void libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_
} }
/* Set socket non blocking */ /* Set socket non blocking */
#ifdef WIN32
{
int flags = 1;
ioctlsocket(conn->fd, FIONBIO, &flags);
}
#else
fcntl(conn->fd, F_SETFL, O_NONBLOCK); fcntl(conn->fd, F_SETFL, O_NONBLOCK);
#endif
connect(conn->fd, (struct sockaddr *) addr, sizeof(*addr)); connect(conn->fd, (struct sockaddr *) addr, sizeof(*addr));
conn->state = OPM_STATE_ESTABLISHED; conn->state = OPM_STATE_ESTABLISHED;

76
opsb.c
View file

@ -155,17 +155,17 @@ int opsb_cmd_check (CmdParams* cmdparams)
} }
scandata = malloc(sizeof(scaninfo)); scandata = malloc(sizeof(scaninfo));
scandata->doneban = 0; scandata->doneban = 0;
scandata->u = cmdparams->source; scandata->reqclient = cmdparams->source;
if ((u2 = find_user(cmdparams->av[0])) != NULL) { if ((u2 = find_user(cmdparams->av[0])) != NULL) {
/* don't scan users from my server */ /* don't scan users from my server */
if (!strcasecmp(u2->user->server->name, me.name)) { if (!strcasecmp(u2->uplink->name, me.name)) {
irc_prefmsg (opsb_bot, cmdparams->source, "Error, Can not scan NeoStats Bots"); irc_prefmsg (opsb_bot, cmdparams->source, "Error, Can not scan NeoStats Bots");
free(scandata); free(scandata);
return -1; return -1;
} }
strlcpy(scandata->who, u2->name, MAXHOST); strlcpy(scandata->who, u2->name, MAXHOST);
strlcpy(scandata->lookup, u2->user->hostname, MAXHOST); strlcpy(scandata->lookup, u2->user->hostname, MAXHOST);
strlcpy(scandata->server, u2->user->server->name, MAXHOST); strlcpy(scandata->server, u2->uplink->name, MAXHOST);
scandata->ip.s_addr = u2->ip.s_addr; scandata->ip.s_addr = u2->ip.s_addr;
if (scandata->ip.s_addr > 0) { if (scandata->ip.s_addr > 0) {
scandata->dnsstate = DO_OPM_LOOKUP; scandata->dnsstate = DO_OPM_LOOKUP;
@ -460,29 +460,12 @@ int checkcache(scaninfo *scandata)
{ {
lnode_t *node, *node2; lnode_t *node, *node2;
cache_entry *ce; cache_entry *ce;
exemptinfo *exempts;
SET_SEGV_LOCATION(); SET_SEGV_LOCATION();
if (scandata->server && IsServerExempt (scandata->who, scandata->server))
node = list_first(exempt); return 1;
while (node) { if (IsUserExempt (scandata->who, scandata->lookup))
exempts = lnode_get(node); return 2;
if ((exempts->server == 1) && (scandata->server)) {
/* match a server */
if (match(exempts->host, scandata->server)) {
dlog (DEBUG1, "OPSB: User %s exempt. Matched server entry %s in Exemptions", scandata->who, exempts->host);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u,"%s Matches a Server Exception %s", scandata->who, exempts->host);
return 1;
}
} else {
if (match(exempts->host, scandata->lookup)) {
dlog (DEBUG1, "OPSB: User %s exempt. Matched host entry %s in exemptions", scandata->who, exempts->host);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "%s Matches a Host Exception %s", scandata->who, exempts->host);
return 2;
}
}
node = list_next(exempt, node);
}
node = list_first(cache); node = list_first(cache);
while (node) { while (node) {
ce = lnode_get(node); ce = lnode_get(node);
@ -501,7 +484,7 @@ int checkcache(scaninfo *scandata)
if (ce->ip == scandata->ip.s_addr) { if (ce->ip == scandata->ip.s_addr) {
dlog (DEBUG1, "OPSB: user %s is already in Cache", scandata->who); dlog (DEBUG1, "OPSB: user %s is already in Cache", scandata->who);
opsb.cachehits++; opsb.cachehits++;
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "User %s is already in Cache", scandata->who); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "User %s is already in Cache", scandata->who);
return 3; return 3;
} }
node = list_next(cache, node); node = list_next(cache, node);
@ -520,30 +503,18 @@ static int ScanNick (CmdParams* cmdparams)
{ {
scaninfo *scandata; scaninfo *scandata;
lnode_t *scannode; lnode_t *scannode;
lnode_t *node;
exemptinfo *exempts;
SET_SEGV_LOCATION(); SET_SEGV_LOCATION();
/* don't scan users from a server that is excluded */ /* don't scan users from a server that is excluded */
node = list_first(exempt); if (IsServerExempt (cmdparams->source->name, cmdparams->source->uplink->name))
while (node) { {
exempts = lnode_get(node); return -1;
if (exempts->server == 1) {
/* match a server */
if (match(exempts->host, cmdparams->source->user->server->name)) {
dlog (DEBUG1, "OPSB: User %s exempt. Matched server entry %s in Exemptions", cmdparams->source->name, exempts->host);
return -1;
}
}
node = list_next(exempt, node);
} }
if (time(NULL) - cmdparams->source->tsconnect > opsb.timedif) { if (time(NULL) - cmdparams->source->tsconnect > opsb.timedif) {
dlog (DEBUG1, "Netsplit Nick %s, Not Scanning", cmdparams->source->name); dlog (DEBUG1, "Netsplit Nick %s, Not Scanning", cmdparams->source->name);
return -1; return -1;
} }
scannode = list_find(opsbl, cmdparams->source->name, findscan); scannode = list_find(opsbl, cmdparams->source->name, findscan);
if (!scannode) scannode = list_find(opsbq, cmdparams->source->name, findscan); if (!scannode) scannode = list_find(opsbq, cmdparams->source->name, findscan);
if (scannode) { if (scannode) {
@ -552,11 +523,11 @@ static int ScanNick (CmdParams* cmdparams)
} }
irc_prefmsg (opsb_bot, cmdparams->source, "%s", opsb.scanmsg); irc_prefmsg (opsb_bot, cmdparams->source, "%s", opsb.scanmsg);
scandata = malloc(sizeof(scaninfo)); scandata = malloc(sizeof(scaninfo));
scandata->u = NULL; scandata->reqclient = NULL;
scandata->doneban = 0; scandata->doneban = 0;
strlcpy(scandata->who, cmdparams->source->name, MAXHOST); strlcpy(scandata->who, cmdparams->source->name, MAXHOST);
strlcpy(scandata->lookup, cmdparams->source->user->hostname, MAXHOST); strlcpy(scandata->lookup, cmdparams->source->user->hostname, MAXHOST);
strlcpy(scandata->server, cmdparams->source->user->server->name, MAXHOST); strlcpy(scandata->server, cmdparams->source->uplink->name, MAXHOST);
strlcpy(scandata->connectstring, recbuf, BUFSIZE); strlcpy(scandata->connectstring, recbuf, BUFSIZE);
scandata->ip.s_addr = cmdparams->source->ip.s_addr; scandata->ip.s_addr = cmdparams->source->ip.s_addr;
if (scandata->ip.s_addr > 0) { if (scandata->ip.s_addr > 0) {
@ -590,7 +561,7 @@ int startscan(scaninfo *scandata)
/* only check the cache when we have IP addy */ /* only check the cache when we have IP addy */
if (scandata->dnsstate == DO_OPM_LOOKUP) { if (scandata->dnsstate == DO_OPM_LOOKUP) {
i = checkcache(scandata); i = checkcache(scandata);
if ((i > 0) && (scandata->u == NULL)) { if ((i > 0) && (scandata->reqclient == NULL)) {
free(scandata); free(scandata);
return 1; return 1;
} }
@ -601,14 +572,14 @@ int startscan(scaninfo *scandata)
if (list_isfull(opsbq)) { if (list_isfull(opsbq)) {
irc_chanalert (opsb_bot, "Warning, Both Current and queue lists are full. Not Adding additional scans"); irc_chanalert (opsb_bot, "Warning, Both Current and queue lists are full. Not Adding additional scans");
dlog (DEBUG1, "OPSB: dropped scaning of %s, as queue is full", scandata->who); dlog (DEBUG1, "OPSB: dropped scaning of %s, as queue is full", scandata->who);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "To Busy. Try again later"); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "To Busy. Try again later");
free(scandata); free(scandata);
return 0; return 0;
} }
scannode = lnode_create(scandata); scannode = lnode_create(scandata);
list_append(opsbq, scannode); list_append(opsbq, scannode);
dlog (DEBUG1, "DNS: Added %s to dns queue", scandata->who); dlog (DEBUG1, "DNS: Added %s to dns queue", scandata->who);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "Your Request has been added to the Queue"); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "Your Request has been added to the Queue");
return 1; return 1;
} }
if (dns_lookup(scandata->lookup, adns_r_a, dnsblscan, scandata->who) != 1) { if (dns_lookup(scandata->lookup, adns_r_a, dnsblscan, scandata->who) != 1) {
@ -627,7 +598,7 @@ int startscan(scaninfo *scandata)
if (list_isfull(opsbl)) { if (list_isfull(opsbl)) {
if(list_isfull(opsbq)) { if(list_isfull(opsbq)) {
irc_chanalert (opsb_bot, "Warning, Both Current and Queue lists are full, Not adding Scan"); irc_chanalert (opsb_bot, "Warning, Both Current and Queue lists are full, Not adding Scan");
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "Too Busy. Try again Later"); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "Too Busy. Try again Later");
free(scandata); free(scandata);
return 0; return 0;
} }
@ -657,7 +628,7 @@ int startscan(scaninfo *scandata)
list_append(opsbl, scannode); list_append(opsbl, scannode);
dlog (DEBUG1, "DNS: Added OPM %s lookup to DNS active list", buf); dlog (DEBUG1, "DNS: Added OPM %s lookup to DNS active list", buf);
free(buf); free(buf);
start_proxy_scan(scannode); start_proxy_scan(lnode_get(scannode));
++opsb.scanned; ++opsb.scanned;
return 1; return 1;
break; break;
@ -690,7 +661,7 @@ void dnsblscan(char *data, adns_answer *a)
case DO_DNS_HOST_LOOKUP: case DO_DNS_HOST_LOOKUP:
if (a->nrrs < 1) { if (a->nrrs < 1) {
irc_chanalert (opsb_bot, "No Record for %s. Aborting Scan", scandata->lookup); irc_chanalert (opsb_bot, "No Record for %s. Aborting Scan", scandata->lookup);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "No A record for %s. Aborting Scan", scandata->lookup); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "No A record for %s. Aborting Scan", scandata->lookup);
list_delete(opsbl, scannode); list_delete(opsbl, scannode);
lnode_destroy(scannode); lnode_destroy(scannode);
free(scandata); free(scandata);
@ -703,7 +674,7 @@ void dnsblscan(char *data, adns_answer *a)
dlog (DEBUG1, "DNS: Got IP for %s -> %s", scandata->who, show); dlog (DEBUG1, "DNS: Got IP for %s -> %s", scandata->who, show);
if (a->nrrs > 1) { if (a->nrrs > 1) {
irc_chanalert (opsb_bot, "Warning, More than one IP address for %s. Using %s only", scandata->lookup, show); irc_chanalert (opsb_bot, "Warning, More than one IP address for %s. Using %s only", scandata->lookup, show);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "Warning, More than one IP address for %s. Using %s only", scandata->lookup, show); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "Warning, More than one IP address for %s. Using %s only", scandata->lookup, show);
} }
if (inet_aton(show, &scandata->ip) > 0) { if (inet_aton(show, &scandata->ip) > 0) {
scandata->dnsstate = DO_OPM_LOOKUP; scandata->dnsstate = DO_OPM_LOOKUP;
@ -737,11 +708,11 @@ void dnsblscan(char *data, adns_answer *a)
opsb.opmhits++; opsb.opmhits++;
irc_chanalert (opsb_bot, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain); irc_chanalert (opsb_bot, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain);
irc_globops (opsb_bot, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain); irc_globops (opsb_bot, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain);
irc_akill (opsb_bot, inet_ntoa(scandata->ip), "*", opsb.bantime, "Your host is listed as an Open Proxy. Please visit the following website for more info: www.blitzed.org/proxy?ip=%s", inet_ntoa(scandata->ip)); irc_akill (opsb_bot, inet_ntoa(scandata->ip), "*", opsb.bantime, "Your host is listed as an Open Proxy. Please visit the following website for more info: www.blitzed.org/proxy?ip=%s", inet_ntoa(scandata->ip));
checkqueue(); checkqueue();
} else { } else {
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "%s does not appear in DNS black list", scandata->lookup); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "%s does not appear in DNS black list", scandata->lookup);
dlog (DEBUG1, "Got Negative OPM lookup for %s (%s)", scandata->who, scandata->lookup); dlog (DEBUG1, "Got Negative OPM lookup for %s (%s)", scandata->who, scandata->lookup);
scandata->dnsstate = NOOPMLIST; scandata->dnsstate = NOOPMLIST;
} }
@ -824,7 +795,6 @@ int ModInit (Module *mod_ptr)
opsbq = list_create(MAX_QUEUE); opsbq = list_create(MAX_QUEUE);
/* scan cache is MAX_QUEUE size (why not?) */ /* scan cache is MAX_QUEUE size (why not?) */
cache = list_create(MAX_QUEUE); cache = list_create(MAX_QUEUE);
exempt = list_create(MAX_EXEMPTS);
opsb.ports = list_create(MAX_PORTS); opsb.ports = list_create(MAX_PORTS);
LoadExempts(); LoadExempts();
opsb.open = 0; opsb.open = 0;
@ -843,4 +813,4 @@ int ModInit (Module *mod_ptr)
void ModFini() void ModFini()
{ {
}; }

8
opsb.h
View file

@ -45,7 +45,7 @@ typedef struct scaninfo{
char lookup[MAXHOST]; char lookup[MAXHOST];
char server[MAXHOST]; char server[MAXHOST];
struct in_addr ip; struct in_addr ip;
Client *u; Client *reqclient;
int doreport; int doreport;
time_t started; time_t started;
int doneban; int doneban;
@ -101,10 +101,6 @@ typedef struct proxy_type {
char name[MAXNICK]; char name[MAXNICK];
} proxy_type; } proxy_type;
/* this is the list of exempted hosts/servers */
list_t *exempt;
/* these are some state flags */ /* these are some state flags */
#define REPORT_DNS 0x0001 #define REPORT_DNS 0x0001
#define DO_DNS_HOST_LOOKUP 0x0002 #define DO_DNS_HOST_LOOKUP 0x0002
@ -124,7 +120,7 @@ void addtocache(unsigned long ip);
/* proxy.c */ /* proxy.c */
void start_proxy_scan(lnode_t *scannode); void start_proxy_scan(scaninfo *scandata);
int opsb_cmd_status (CmdParams* cmdparams) ; int opsb_cmd_status (CmdParams* cmdparams) ;
void check_scan_free(scaninfo *scandata); void check_scan_free(scaninfo *scandata);
int init_libopm(); int init_libopm();

44
proxy.c
View file

@ -34,6 +34,7 @@
#endif #endif
#include "neostats.h" #include "neostats.h"
#include "opsb.h" #include "opsb.h"
#include "exempts.h"
#include "opm.h" #include "opm.h"
#include "opm_types.h" #include "opm_types.h"
#include "opm_error.h" #include "opm_error.h"
@ -178,7 +179,7 @@ void open_proxy(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused)
nlog (LOG_CRITICAL, "OPSB: Banning %s (%s) for Open Proxy - %s(%d)", scandata->who, remote->ip, type_of_proxy(remote->protocol), remote->port); nlog (LOG_CRITICAL, "OPSB: Banning %s (%s) for Open Proxy - %s(%d)", scandata->who, remote->ip, type_of_proxy(remote->protocol), remote->port);
irc_chanalert (opsb_bot, "Banning %s (%s) for Open Proxy - %s(%d)", scandata->who, remote->ip, type_of_proxy(remote->protocol), remote->port); irc_chanalert (opsb_bot, "Banning %s (%s) for Open Proxy - %s(%d)", scandata->who, remote->ip, type_of_proxy(remote->protocol), remote->port);
irc_globops (opsb_bot, "Banning %s (%s) for Open Proxy - %s(%d)", scandata->who, remote->ip, type_of_proxy(remote->protocol), remote->port); irc_globops (opsb_bot, "Banning %s (%s) for Open Proxy - %s(%d)", scandata->who, remote->ip, type_of_proxy(remote->protocol), remote->port);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "Banning %s (%s) for Open Proxy - %s(%d)", scandata->who, remote->ip, type_of_proxy(remote->protocol), remote->port); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "Banning %s (%s) for Open Proxy - %s(%d)", scandata->who, remote->ip, type_of_proxy(remote->protocol), remote->port);
if (opsb.doban) if (opsb.doban)
irc_akill (opsb_bot, remote->ip, "*", opsb.bantime, "Open Proxy found on your host. %s(%d)", type_of_proxy(remote->protocol), remote->port); irc_akill (opsb_bot, remote->ip, "*", opsb.bantime, "Open Proxy found on your host. %s(%d)", type_of_proxy(remote->protocol), remote->port);
#if 0 #if 0
@ -198,7 +199,7 @@ void open_proxy(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused)
nlog (LOG_CRITICAL, "OPSB: Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain); nlog (LOG_CRITICAL, "OPSB: Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain);
irc_chanalert (opsb_bot, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain); irc_chanalert (opsb_bot, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain);
irc_globops (opsb_bot, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain); irc_globops (opsb_bot, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain);
if (scandata->u) irc_prefmsg (opsb_bot, scandata->u, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain); if (scandata->reqclient) irc_prefmsg (opsb_bot, scandata->reqclient, "Banning %s (%s) as its listed in %s", scandata->who, inet_ntoa(scandata->ip), opsb.opmdomain);
irc_akill (opsb_bot, inet_ntoa(scandata->ip), "*", opsb.bantime, "Your host is listed as an Open Proxy. Please visit the following website for more info: www.blitzed.org/proxy?ip=%s", inet_ntoa(scandata->ip)); irc_akill (opsb_bot, inet_ntoa(scandata->ip), "*", opsb.bantime, "Your host is listed as an Open Proxy. Please visit the following website for more info: www.blitzed.org/proxy?ip=%s", inet_ntoa(scandata->ip));
} }
#endif #endif
@ -211,8 +212,8 @@ void negfailed(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused)
scandata = remote->data; scandata = remote->data;
if (scandata->u) { if (scandata->reqclient) {
irc_prefmsg (opsb_bot, scandata->u, "Negitiation failed for protocol %s(%d)", type_of_proxy(remote->protocol), remote->port); irc_prefmsg (opsb_bot, scandata->reqclient, "Negitiation failed for protocol %s(%d)", type_of_proxy(remote->protocol), remote->port);
} }
} }
@ -222,8 +223,8 @@ void timeout(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused) {
SET_SEGV_LOCATION(); SET_SEGV_LOCATION();
scandata = remote->data; scandata = remote->data;
if (scandata->u) { if (scandata->reqclient) {
irc_prefmsg (opsb_bot, scandata->u, "Timeout on Protocol %s(%d)", type_of_proxy(remote->protocol), remote->port); irc_prefmsg (opsb_bot, scandata->reqclient, "Timeout on Protocol %s(%d)", type_of_proxy(remote->protocol), remote->port);
} }
} }
@ -233,8 +234,8 @@ void scan_end(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused) {
SET_SEGV_LOCATION(); SET_SEGV_LOCATION();
scandata = remote->data; scandata = remote->data;
if (scandata->u) { if (scandata->reqclient) {
irc_prefmsg (opsb_bot, scandata->u, "scan finished on %s", scandata->who); irc_prefmsg (opsb_bot, scandata->reqclient, "scan finished on %s", scandata->who);
} }
opm_remote_free(remote); opm_remote_free(remote);
if (scandata->state != GOTOPENPROXY) scandata->state = FIN_SCAN; if (scandata->state != GOTOPENPROXY) scandata->state = FIN_SCAN;
@ -246,11 +247,11 @@ void scan_error(OPM_T *scanner, OPM_REMOTE_T *remote, int opmerr, void *unused)
SET_SEGV_LOCATION(); SET_SEGV_LOCATION();
scandata = remote->data; scandata = remote->data;
if (scandata->u) { if (scandata->reqclient) {
if (opmerr == 5) { if (opmerr == 5) {
irc_prefmsg (opsb_bot, scandata->u, "Closed Proxy on Protocol %s (%d)", type_of_proxy(remote->protocol), remote->port); irc_prefmsg (opsb_bot, scandata->reqclient, "Closed Proxy on Protocol %s (%d)", type_of_proxy(remote->protocol), remote->port);
} else { } else {
irc_prefmsg (opsb_bot, scandata->u, "scan error on Protocol %s (%d) - %d", type_of_proxy(remote->protocol), remote->port, opmerr); irc_prefmsg (opsb_bot, scandata->reqclient, "scan error on Protocol %s (%d) - %d", type_of_proxy(remote->protocol), remote->port, opmerr);
} }
} }
@ -266,7 +267,7 @@ int opsb_cmd_status (CmdParams* cmdparams)
SET_SEGV_LOCATION(); SET_SEGV_LOCATION();
irc_prefmsg (opsb_bot, cmdparams->source, "Proxy Results:"); irc_prefmsg (opsb_bot, cmdparams->source, "Proxy Results:");
irc_prefmsg (opsb_bot, cmdparams->source, "Hosts Scanned: %d Hosts found Open: %d Exceptions %d", opsb.scanned, opsb.open, (int)list_count(exempt)); irc_prefmsg (opsb_bot, cmdparams->source, "Hosts Scanned: %d Hosts found Open: %d Exceptions %d", opsb.scanned, opsb.open, GetExemptCount ());
irc_prefmsg (opsb_bot, cmdparams->source, "Cache Entries: %d", (int)list_count(cache)); irc_prefmsg (opsb_bot, cmdparams->source, "Cache Entries: %d", (int)list_count(cache));
irc_prefmsg (opsb_bot, cmdparams->source, "Cache Hits: %d", opsb.cachehits); irc_prefmsg (opsb_bot, cmdparams->source, "Cache Hits: %d", opsb.cachehits);
irc_prefmsg (opsb_bot, cmdparams->source, "Blacklist Hits: %d", opsb.opmhits); irc_prefmsg (opsb_bot, cmdparams->source, "Blacklist Hits: %d", opsb.opmhits);
@ -279,8 +280,8 @@ int opsb_cmd_status (CmdParams* cmdparams)
node = list_first(opsbl); node = list_first(opsbl);
while (node) { while (node) {
scandata = lnode_get(node); scandata = lnode_get(node);
if (scandata->u) if (scandata->reqclient)
irc_prefmsg (opsb_bot, cmdparams->source, "Scanning %s by request of %s", scandata->lookup, scandata->u->name); irc_prefmsg (opsb_bot, cmdparams->source, "Scanning %s by request of %s", scandata->lookup, scandata->reqclient->name);
else else
irc_prefmsg (opsb_bot, cmdparams->source, "Scanning %s (%s) - %s", scandata->lookup, inet_ntoa(scandata->ip), scandata->who); irc_prefmsg (opsb_bot, cmdparams->source, "Scanning %s (%s) - %s", scandata->lookup, inet_ntoa(scandata->ip), scandata->who);
@ -319,28 +320,25 @@ int opsb_cmd_status (CmdParams* cmdparams)
} }
void start_proxy_scan(lnode_t *scannode) { void start_proxy_scan(scaninfo *scandata)
scaninfo *scandata; {
OPM_REMOTE_T *remote; OPM_REMOTE_T *remote;
int i; int i;
SET_SEGV_LOCATION(); SET_SEGV_LOCATION();
scandata = lnode_get(scannode);
/* if we are configured not to scan, and its not a request, bail out */ /* if we are configured not to scan, and its not a request, bail out */
if ((opsb.doscan == 0) && (!scandata->u)) { if ((opsb.doscan == 0) && (!scandata->reqclient)) {
scandata->state = FIN_SCAN; scandata->state = FIN_SCAN;
check_scan_free(scandata); check_scan_free(scandata);
return; return;
} }
if (scandata->u) irc_chanalert (opsb_bot, "Starting proxy scan on %s (%s) by Request of %s", scandata->who, scandata->lookup, scandata->u->name); if (scandata->reqclient) irc_chanalert (opsb_bot, "Starting proxy scan on %s (%s) by Request of %s", scandata->who, scandata->lookup, scandata->reqclient->name);
scandata->state = DOING_SCAN; scandata->state = DOING_SCAN;
/* this is so we can timeout scans */ /* this is so we can timeout scans */
scandata->started = time(NULL); scandata->started = time(NULL);
if ((opsb.doscan == 1) || (scandata->u)) { if ((opsb.doscan == 1) || (scandata->reqclient)) {
remote = opm_remote_create(inet_ntoa(scandata->ip)); remote = opm_remote_create(inet_ntoa(scandata->ip));
remote->data = scandata; remote->data = scandata;
switch(i = opm_scan(scanner, remote)) switch(i = opm_scan(scanner, remote))
@ -372,7 +370,7 @@ void check_scan_free(scaninfo *scandata) {
dlog (DEBUG1, "%s scan finished. Cleaning up", scandata->who); dlog (DEBUG1, "%s scan finished. Cleaning up", scandata->who);
list_delete(opsbl, scannode); list_delete(opsbl, scannode);
lnode_destroy(scannode); lnode_destroy(scannode);
scandata->u = NULL; scandata->reqclient = NULL;
free(scandata); free(scandata);
} else { } else {
nlog (LOG_WARNING, "Damn, Can't find ScanNode %s. Something is fubar", scandata->who); nlog (LOG_WARNING, "Damn, Can't find ScanNode %s. Something is fubar", scandata->who);