Update OPSB to take advantage of nickip support in the core to reduce double lookups on IRCd's that don't provide NICKIP support and statserv etc is loaded and fix a problem with disablescan the queue list growing

This commit is contained in:
Fish 2004-07-06 12:10:07 +00:00
parent 86430b117e
commit 663920790b
4 changed files with 29 additions and 22 deletions

View file

@ -8,6 +8,8 @@ Open Proxy Scanning Bot Module for NeoStats Changelog.
- Ported to core command processor (M) - Ported to core command processor (M)
- Add verbose option so we can turn off some messages from OPSB (M) - Add verbose option so we can turn off some messages from OPSB (M)
- Fixed socklen_t compile problems on older bsd's (F) - Fixed socklen_t compile problems on older bsd's (F)
- OPSB now uses the core's NICKIP support rather than our own. This will reduce double lookups on hostnames for IRCd's that don't provide NICKIP (F)
- Fix a problem where when disablescan was enabled, the scan queue would grow out of control (F)
* Version 2.1 * 24/01/2004 * Fish (F) * Version 2.1 * 24/01/2004 * Fish (F)
- Sync up libopm with blitzed version to fix a Socks 5 bug (F) - Sync up libopm with blitzed version to fix a Socks 5 bug (F)

36
opsb.c
View file

@ -152,6 +152,7 @@ int do_check(User *u, char **argv, int argc)
/* don't scan users from my server */ /* don't scan users from my server */
if (!strcasecmp(u2->server->name, me.name)) { if (!strcasecmp(u2->server->name, me.name)) {
prefmsg(u->nick, s_opsb, "Error, Can not scan NeoStats Bots"); prefmsg(u->nick, s_opsb, "Error, Can not scan NeoStats Bots");
free(scandata);
return -1; return -1;
} }
strlcpy(scandata->who, u2->nick, MAXHOST); strlcpy(scandata->who, u2->nick, MAXHOST);
@ -161,21 +162,20 @@ int do_check(User *u, char **argv, int argc)
if (scandata->ipaddr.s_addr > 0) { if (scandata->ipaddr.s_addr > 0) {
scandata->dnsstate = DO_OPM_LOOKUP; scandata->dnsstate = DO_OPM_LOOKUP;
} else { } else {
if (inet_aton(u2->hostname, &scandata->ipaddr) > 0) /* if its here, we don't have the IP address yet */
scandata->dnsstate = DO_OPM_LOOKUP; prefmsg(u->nick, s_opsb, "Error: We don't have a IP address for %s yet. Try again soon", u2->nick);
else { free(scandata);
scandata->dnsstate = GET_NICK_IP; return -1;
scandata->ipaddr.s_addr = 0;
}
} }
} else { } else {
strlcpy(scandata->who, argv[2], MAXHOST); strlcpy(scandata->who, argv[2], MAXHOST);
strlcpy(scandata->lookup, argv[2], MAXHOST); strlcpy(scandata->lookup, argv[2], MAXHOST);
bzero(scandata->server, MAXHOST); bzero(scandata->server, MAXHOST);
/* is it a ip address or host */
if (inet_aton(argv[2], &scandata->ipaddr) > 0) { if (inet_aton(argv[2], &scandata->ipaddr) > 0) {
scandata->dnsstate = DO_OPM_LOOKUP; scandata->dnsstate = DO_OPM_LOOKUP;
} else { } else {
scandata->dnsstate = GET_NICK_IP; scandata->dnsstate = DO_DNS_HOST_LOOKUP;
scandata->ipaddr.s_addr = 0; scandata->ipaddr.s_addr = 0;
} }
} }
@ -573,7 +573,7 @@ int checkcache(scaninfo *scandata) {
EventFnList __module_events[] = { EventFnList __module_events[] = {
{ EVENT_ONLINE, Online}, { EVENT_ONLINE, Online},
{ EVENT_SIGNON, ScanNick}, { EVENT_GOTNICKIP, ScanNick},
{ NULL, NULL} { NULL, NULL}
}; };
@ -639,20 +639,16 @@ static int ScanNick(char **av, int ac) {
if (scandata->ipaddr.s_addr > 0) { if (scandata->ipaddr.s_addr > 0) {
scandata->dnsstate = DO_OPM_LOOKUP; scandata->dnsstate = DO_OPM_LOOKUP;
} else { } else {
if (inet_aton(u->hostname, &scandata->ipaddr) > 0) /* if we get here, and don't have a IP address, something is fcked up */
scandata->dnsstate = DO_OPM_LOOKUP; nlog(LOG_WARNING, LOG_MOD, "Eh, Event_GOTNICKIP called without a IP for %s", u->nick);
else { free(scandata);
scandata->dnsstate = GET_NICK_IP; return -1;
scandata->ipaddr.s_addr = 0;
}
} }
if (!startscan(scandata)) { if (!startscan(scandata)) {
chanalert(s_opsb, "Warning Can't scan %s", u->nick); chanalert(s_opsb, "Warning Can't scan %s", u->nick);
nlog(LOG_WARNING, LOG_MOD, "OBSB ScanNick(): Can't scan %s. Check logs for possible errors", u->nick); nlog(LOG_WARNING, LOG_MOD, "OBSB ScanNick(): Can't scan %s. Check logs for possible errors", u->nick);
} }
return 1; return 1;
} }
/* this function is the entry point for all scans. Any scan you want to kick off is started with this function. */ /* this function is the entry point for all scans. Any scan you want to kick off is started with this function. */
@ -676,7 +672,7 @@ int startscan(scaninfo *scandata) {
} }
} }
switch(scandata->dnsstate) { switch(scandata->dnsstate) {
case GET_NICK_IP: case DO_DNS_HOST_LOOKUP:
if (list_isfull(opsbl)) { if (list_isfull(opsbl)) {
if (list_isfull(opsbq)) { if (list_isfull(opsbq)) {
chanalert(s_opsb, "Warning, Both Current and queue lists are full. Not Adding additional scans"); chanalert(s_opsb, "Warning, Both Current and queue lists are full. Not Adding additional scans");
@ -692,7 +688,7 @@ int startscan(scaninfo *scandata) {
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) {
nlog(LOG_WARNING, LOG_MOD, "DNS: startscan() GET_NICK_IP dns_lookup() failed"); nlog(LOG_WARNING, LOG_MOD, "DNS: startscan() DO_DNS_HOST_LOOKUP dns_lookup() failed");
free(scandata); free(scandata);
checkqueue(); checkqueue();
return 0; return 0;
@ -766,7 +762,7 @@ void dnsblscan(char *data, adns_answer *a) {
scandata = lnode_get(scannode); scandata = lnode_get(scannode);
if (a) { if (a) {
switch(scandata->dnsstate) { switch(scandata->dnsstate) {
case GET_NICK_IP: case DO_DNS_HOST_LOOKUP:
if (a->nrrs < 1) { if (a->nrrs < 1) {
chanalert(s_opsb, "No Record for %s. Aborting Scan", scandata->lookup); chanalert(s_opsb, "No Record for %s. Aborting Scan", scandata->lookup);
if (scandata->u) prefmsg(scandata->u->nick, s_opsb, "No A record for %s. Aborting Scan", scandata->lookup); if (scandata->u) prefmsg(scandata->u->nick, s_opsb, "No A record for %s. Aborting Scan", scandata->lookup);
@ -1043,6 +1039,8 @@ int __ModInit(int modnum, int apiver)
return -1; return -1;
} }
init_libopm(); init_libopm();
/* tell NeoStats we want nickip */
me.want_nickip = 1;
return 1; return 1;
} }

2
opsb.h
View file

@ -124,7 +124,7 @@ list_t *exempt;
/* these are some state flags */ /* these are some state flags */
#define REPORT_DNS 0x0001 #define REPORT_DNS 0x0001
#define GET_NICK_IP 0x0002 #define DO_DNS_HOST_LOOKUP 0x0002
#define DO_OPM_LOOKUP 0x0004 #define DO_OPM_LOOKUP 0x0004
#define DOING_SCAN 0x0008 #define DOING_SCAN 0x0008
#define GOTOPENPROXY 0x0010 #define GOTOPENPROXY 0x0010

11
proxy.c
View file

@ -285,7 +285,7 @@ int do_status(User *u, char **av, int ac)
case REPORT_DNS: case REPORT_DNS:
prefmsg(u->nick, s_opsb, "Looking up IP Address"); prefmsg(u->nick, s_opsb, "Looking up IP Address");
break; break;
case GET_NICK_IP: case DO_DNS_HOST_LOOKUP:
prefmsg(u->nick, s_opsb, "Looking up IP address for Scan"); prefmsg(u->nick, s_opsb, "Looking up IP address for Scan");
break; break;
case DO_OPM_LOOKUP: case DO_OPM_LOOKUP:
@ -325,6 +325,13 @@ void start_proxy_scan(lnode_t *scannode) {
scandata = lnode_get(scannode); scandata = lnode_get(scannode);
/* if we are configured not to scan, and its not a request, bail out */
if ((opsb.doscan == 0) && (!scandata->u)) {
scandata->state = FIN_SCAN;
check_scan_free(scandata);
return;
}
if (scandata->u) chanalert(s_opsb, "Starting proxy scan on %s (%s) by Request of %s", scandata->who, scandata->lookup, scandata->u->nick); if (scandata->u) chanalert(s_opsb, "Starting proxy scan on %s (%s) by Request of %s", scandata->who, scandata->lookup, scandata->u->nick);
scandata->state = DOING_SCAN; scandata->state = DOING_SCAN;
/* this is so we can timeout scans */ /* this is so we can timeout scans */
@ -349,7 +356,7 @@ void start_proxy_scan(lnode_t *scannode) {
} }
void check_scan_free(scaninfo *scandata) { void check_scan_free(scaninfo *scandata) {
lnode_t *scannode; lnode_t *scannode;
if ((scandata->dnsstate == DO_OPM_LOOKUP) || (scandata->dnsstate == GET_NICK_IP) || (scandata->state == DOING_SCAN)) { if ((scandata->dnsstate == DO_OPM_LOOKUP) || (scandata->dnsstate == DO_DNS_HOST_LOOKUP) || (scandata->state == DOING_SCAN)) {
nlog(LOG_DEBUG2, LOG_MOD, "Not Cleaning up Scaninfo for %s yet. Scan hasn't completed", scandata->who); nlog(LOG_DEBUG2, LOG_MOD, "Not Cleaning up Scaninfo for %s yet. Scan hasn't completed", scandata->who);
return; return;
} }