add code comments and some tidy ups
This commit is contained in:
parent
38b55be3f9
commit
8e59946a69
3 changed files with 329 additions and 193 deletions
422
blsb.c
422
blsb.c
|
@ -21,6 +21,18 @@
|
|||
** $Id$
|
||||
*/
|
||||
|
||||
/* TODO:
|
||||
* - Akill support.
|
||||
* - Buffer sizes for name and domain should not need to be so big
|
||||
* so should be made a more appropriate size.
|
||||
* - If a remove akill command is added, it must check whether an akill.
|
||||
* was added by blsb before removing it otherwise blsb becomes a way
|
||||
* for opers to remove any akill on the network.
|
||||
* - Since name and domain must both be unique, suggest that DEL takes
|
||||
* domain as a parameter for delete rather than an index. More intuitive
|
||||
* for users.
|
||||
*/
|
||||
|
||||
#include "neostats.h"
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
|
@ -31,13 +43,13 @@
|
|||
#include "blsb.h"
|
||||
|
||||
Bot *blsb_bot;
|
||||
static int ss_event_signon( CmdParams* cmdparams );
|
||||
int blsb_cmd_domains_list( CmdParams* cmdparams );
|
||||
int blsb_cmd_domains_add( CmdParams* cmdparams );
|
||||
int blsb_cmd_domains_del( CmdParams* cmdparams );
|
||||
int blsb_cmd_domains (CmdParams* cmdparams);
|
||||
int blsb_cmd_check (CmdParams* cmdparams);
|
||||
void dnsbl_callback(void *data, adns_answer *a);
|
||||
static int event_nickip( CmdParams* cmdparams );
|
||||
static int blsb_cmd_list( CmdParams* cmdparams );
|
||||
static int blsb_cmd_add( CmdParams* cmdparams );
|
||||
static int blsb_cmd_del( CmdParams* cmdparams );
|
||||
static int blsb_cmd_check( CmdParams* cmdparams );
|
||||
static int blsb_set_exclusions_cb( CmdParams *cmdparams, SET_REASON reason );
|
||||
void dnsbl_callback( void *data, adns_answer *a );
|
||||
|
||||
static dom_list stddomlist[] = {
|
||||
{"Blitzed OPM", "opm.blitzed.org", 1},
|
||||
|
@ -54,8 +66,8 @@ const char *blsb_copyright[] = {
|
|||
};
|
||||
|
||||
/** Module Info definition
|
||||
* version information about our module
|
||||
* This structure is required for your module to load and run on NeoStats
|
||||
* version information about our module
|
||||
* This structure is required for your module to load and run on NeoStats
|
||||
*/
|
||||
ModuleInfo module_info = {
|
||||
"BLSB",
|
||||
|
@ -70,32 +82,23 @@ ModuleInfo module_info = {
|
|||
0,
|
||||
};
|
||||
|
||||
static int blsb_set_exclusions_cb( CmdParams *cmdparams, SET_REASON reason )
|
||||
{
|
||||
if( reason == SET_LOAD || reason == SET_CHANGE )
|
||||
{
|
||||
SetAllEventFlags( EVENT_FLAG_USE_EXCLUDE, blsb.exclusions );
|
||||
}
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
static bot_cmd blsb_commands[]=
|
||||
{
|
||||
{"ADD", blsb_cmd_domains_add, 3, NS_ULEVEL_ADMIN, blsb_help_domains_add, blsb_help_domains_add_oneline},
|
||||
{"DEL", blsb_cmd_domains_del, 1, NS_ULEVEL_ADMIN, blsb_help_domains_del, blsb_help_domains_del_oneline},
|
||||
{"LIST", blsb_cmd_domains_list, 0, NS_ULEVEL_ADMIN, blsb_help_domains_list, blsb_help_domains_list_oneline},
|
||||
{"CHECK", blsb_cmd_check, 1, NS_ULEVEL_OPER, blsb_help_check, blsb_help_check_oneline},
|
||||
{NULL, NULL, 0, 0, NULL, NULL}
|
||||
{"ADD", blsb_cmd_add, 3, NS_ULEVEL_ADMIN, blsb_help_add, blsb_help_add_oneline},
|
||||
{"DEL", blsb_cmd_del, 1, NS_ULEVEL_ADMIN, blsb_help_del, blsb_help_del_oneline},
|
||||
{"LIST", blsb_cmd_list, 0, NS_ULEVEL_ADMIN, blsb_help_list, blsb_help_list_oneline},
|
||||
{"CHECK", blsb_cmd_check, 1, NS_ULEVEL_OPER, blsb_help_check, blsb_help_check_oneline},
|
||||
{NULL, NULL, 0, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
static bot_setting blsb_settings[]=
|
||||
{
|
||||
{"AKILL", &blsb.doakill, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, blsb_help_set_akill, NULL, (void*)1 },
|
||||
{"AKILL", &blsb.doakill, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, blsb_help_set_akill, NULL, (void*)1 },
|
||||
{"AKILLTIME", &blsb.akilltime, SET_TYPE_INT, 0, 20736000,NS_ULEVEL_ADMIN, NULL, blsb_help_set_akilltime, NULL, (void*)86400 },
|
||||
{"CACHETIME", &blsb.cachetime, SET_TYPE_INT, 0, 86400, NS_ULEVEL_ADMIN, NULL, blsb_help_set_cachetime, NULL, (void*)3600 },
|
||||
{"VERBOSE", &blsb.verbose, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, blsb_help_set_verbose, NULL, (void*)1 },
|
||||
{"VERBOSE", &blsb.verbose, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, blsb_help_set_verbose, NULL, (void*)1 },
|
||||
{"EXCLUSIONS", &blsb.exclusions, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, blsb_help_set_exclusions, blsb_set_exclusions_cb, (void *)0 },
|
||||
{NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL },
|
||||
{NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
/** BotInfo */
|
||||
|
@ -113,11 +116,45 @@ static BotInfo blsb_botinfo =
|
|||
|
||||
ModuleEvent module_events[] =
|
||||
{
|
||||
{ EVENT_NICKIP, ss_event_signon, EVENT_FLAG_EXCLUDE_ME},
|
||||
{ EVENT_NICKIP, event_nickip, EVENT_FLAG_EXCLUDE_ME},
|
||||
{ EVENT_NULL, NULL}
|
||||
};
|
||||
|
||||
int blsb_cmd_domains_list (CmdParams* cmdparams)
|
||||
/** @brief new_bldomain
|
||||
*
|
||||
* Allocate a new blacklist domain entry and add to the list
|
||||
*
|
||||
* @param name of service
|
||||
* @param domain of service
|
||||
* @param type of service
|
||||
*
|
||||
* @return pointer to newly allocated entry
|
||||
*/
|
||||
|
||||
static dom_list *new_bldomain( char *name, char *domain, int type )
|
||||
{
|
||||
dom_list *dl;
|
||||
|
||||
dl = ns_calloc( sizeof( dom_list ) );
|
||||
strlcpy( dl->name, name, BUFSIZE );
|
||||
strlcpy( dl->domain, domain, BUFSIZE );
|
||||
dl->type = type;
|
||||
lnode_create_append( blsb.domains, dl );
|
||||
DBAStore( "domains", dl->name, (void *)dl, sizeof( dom_list ) );
|
||||
return dl;
|
||||
}
|
||||
|
||||
/** @brief blsb_cmd_list
|
||||
*
|
||||
* LIST command handler
|
||||
* List entries in the blacklist domain list
|
||||
*
|
||||
* @param cmdparam struct
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else result of command
|
||||
*/
|
||||
|
||||
int blsb_cmd_list( CmdParams* cmdparams )
|
||||
{
|
||||
dom_list *dl;
|
||||
int i;
|
||||
|
@ -125,7 +162,7 @@ int blsb_cmd_domains_list (CmdParams* cmdparams)
|
|||
|
||||
lnode = list_first(blsb.domains);
|
||||
i = 1;
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "BlackList Domains Listing:");
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "BlackList domains:");
|
||||
while (lnode) {
|
||||
dl = lnode_get(lnode);
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "%d) %s Domain: %s Type: %d", i, dl->name, dl->domain, dl->type);
|
||||
|
@ -133,26 +170,37 @@ int blsb_cmd_domains_list (CmdParams* cmdparams)
|
|||
lnode = list_next(blsb.domains, lnode);
|
||||
}
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "End of list.");
|
||||
CommandReport(blsb_bot, "%s requested BlackList Domain Listing", cmdparams->source->name);
|
||||
CommandReport(blsb_bot, "%s requested blacklist domain list", cmdparams->source->name);
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
/* ./msg blsb domains add <name> <type> <domain> */
|
||||
int blsb_cmd_domains_add (CmdParams* cmdparams)
|
||||
/** @brief blsb_cmd_add
|
||||
*
|
||||
* ADD command handler
|
||||
* Add an entry to the blacklist domain list
|
||||
*
|
||||
* @param cmdparam struct
|
||||
* cmdparams->av[0] = name
|
||||
* cmdparams->av[1] = domain
|
||||
* cmdparams->av[2] = type
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else result of command
|
||||
*/
|
||||
|
||||
int blsb_cmd_add( CmdParams* cmdparams )
|
||||
{
|
||||
dom_list *dl;
|
||||
lnode_t *lnode;
|
||||
int type;
|
||||
|
||||
if (cmdparams->ac < 3) {
|
||||
return NS_ERR_SYNTAX_ERROR;
|
||||
}
|
||||
if (list_isfull(blsb.domains)) {
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Error, Domains list is full");
|
||||
return NS_SUCCESS;
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Error, domain list is full");
|
||||
return NS_FAILURE;
|
||||
}
|
||||
if (!atoi(cmdparams->av[2])) {
|
||||
type = atoi(cmdparams->av[2]);
|
||||
if (!type) {
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "type field does not contain a valid type");
|
||||
return NS_SUCCESS;
|
||||
return NS_FAILURE;
|
||||
}
|
||||
/* XXX do a initial lookup on the domain to check it exists? */
|
||||
|
||||
|
@ -161,60 +209,71 @@ int blsb_cmd_domains_add (CmdParams* cmdparams)
|
|||
while (lnode) {
|
||||
dl = lnode_get(lnode);
|
||||
if ((!ircstrcasecmp(dl->name, cmdparams->av[1])) || (!ircstrcasecmp(dl->domain, cmdparams->av[3]))) {
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Duplicate Entry for Domain %s", cmdparams->av[1]);
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "%s already has an entry", cmdparams->av[1]);
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
lnode = list_next(blsb.domains, lnode);
|
||||
}
|
||||
dl = malloc(sizeof(dom_list));
|
||||
strlcpy(dl->name, cmdparams->av[1], BUFSIZE);
|
||||
strlcpy(dl->domain, cmdparams->av[3], BUFSIZE);
|
||||
dl->type = atoi(cmdparams->av[2]);
|
||||
|
||||
lnode_create_append(blsb.domains, dl);
|
||||
DBAStore("domains", dl->name, (void *)dl, sizeof(dom_list));
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Added Domain %s(%s) as type %d to Domains list", dl->name, dl->domain, dl->type);
|
||||
CommandReport(blsb_bot, "%s added Domain %s(%s) as type %d to Domains list", cmdparams->source->name, dl->name, dl->domain, dl->type);
|
||||
dl = new_bldomain( cmdparams->av[1], cmdparams->av[3], type );
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Added domain %s(%s) as type %d", dl->name, dl->domain, dl->type);
|
||||
CommandReport(blsb_bot, "%s added domain %s(%s) as type %d", cmdparams->source->name, dl->name, dl->domain, dl->type);
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
int blsb_cmd_domains_del (CmdParams* cmdparams)
|
||||
/** @brief blsb_cmd_del
|
||||
*
|
||||
* DEL command handler
|
||||
* deletes an entry from the blacklist domain list
|
||||
*
|
||||
* @param cmdparam struct
|
||||
* cmdparams->av[0] = entry index
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else result of command
|
||||
*/
|
||||
|
||||
int blsb_cmd_del( CmdParams* cmdparams )
|
||||
{
|
||||
dom_list *dl;
|
||||
int i;
|
||||
int i, entryindex;
|
||||
lnode_t *lnode;
|
||||
|
||||
if (cmdparams->ac < 1) {
|
||||
return NS_ERR_SYNTAX_ERROR;
|
||||
}
|
||||
if (atoi(cmdparams->av[1]) != 0) {
|
||||
lnode = list_first(blsb.domains);
|
||||
i = 1;
|
||||
while (lnode) {
|
||||
if (i == atoi(cmdparams->av[1])) {
|
||||
/* delete the entry */
|
||||
dl = lnode_get(lnode);
|
||||
list_delete(blsb.domains, lnode);
|
||||
lnode_destroy(lnode);
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Deleted Blacklist Domain %s (%s) out of domains list", dl->name, dl->domain);
|
||||
CommandReport(blsb_bot, "%s deleted Blacklist Domain %s (%s) out of domains list", cmdparams->source->name, dl->name, dl->domain);
|
||||
DBADelete("domains", dl->name);
|
||||
ns_free(dl);
|
||||
/* just to be sure, lets sort the list */
|
||||
return 1;
|
||||
}
|
||||
++i;
|
||||
lnode = list_next(blsb.domains, lnode);
|
||||
}
|
||||
/* if we get here, then we can't find the entry */
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Error, Can't find entry %d. /msg %s domains list", atoi(cmdparams->av[1]), blsb_bot->name);
|
||||
} else {
|
||||
entryindex = atoi( cmdparams->av[1] );
|
||||
if ( entryindex == 0) {
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Error, Out of Range");
|
||||
return NS_FAILURE;
|
||||
}
|
||||
return NS_SUCCESS;
|
||||
lnode = list_first(blsb.domains);
|
||||
i = 1;
|
||||
while (lnode) {
|
||||
if (i == entryindex) {
|
||||
/* delete the entry */
|
||||
dl = lnode_get(lnode);
|
||||
list_delete(blsb.domains, lnode);
|
||||
lnode_destroy(lnode);
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Deleted Blacklist Domain %s (%s) out of domains list", dl->name, dl->domain);
|
||||
CommandReport(blsb_bot, "%s deleted Blacklist Domain %s (%s) out of domains list", cmdparams->source->name, dl->name, dl->domain);
|
||||
DBADelete("domains", dl->name);
|
||||
ns_free(dl);
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
++i;
|
||||
lnode = list_next(blsb.domains, lnode);
|
||||
}
|
||||
/* if we get here, then we can't find the entry */
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Error, Can't find entry %d. /msg %s domains list", entryindex, blsb_bot->name);
|
||||
return NS_FAILURE;
|
||||
}
|
||||
|
||||
int blsb_cmd_check (CmdParams* cmdparams)
|
||||
/** @brief blsb_cmd_check
|
||||
*
|
||||
* CHECK command handler
|
||||
*
|
||||
* @param cmdparam struct
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else result of command
|
||||
*/
|
||||
|
||||
int blsb_cmd_check( CmdParams* cmdparams )
|
||||
{
|
||||
Client *user;
|
||||
lnode_t *node;
|
||||
|
@ -232,35 +291,35 @@ int blsb_cmd_check (CmdParams* cmdparams)
|
|||
irc_prefmsg(blsb_bot, cmdparams->source, "Invalid Nick or Host");
|
||||
return NS_FAILURE;
|
||||
} else {
|
||||
sc = ns_malloc(sizeof(scanclient));
|
||||
sc->check = 1;
|
||||
sc->user = cmdparams->source;
|
||||
sc->domain = dl;
|
||||
sc->lookup = ns_malloc(buflen);
|
||||
ircsnprintf(sc->lookup, buflen, "%d.%d.%d.%d.%s", d, c, b, a, dl->domain);
|
||||
sc = ns_malloc(sizeof(scanclient));
|
||||
sc->check = 1;
|
||||
sc->user = cmdparams->source;
|
||||
sc->domain = dl;
|
||||
sc->lookup = ns_malloc(buflen);
|
||||
ircsnprintf(sc->lookup, buflen, "%d.%d.%d.%d.%s", d, c, b, a, dl->domain);
|
||||
#endif
|
||||
irc_prefmsg(blsb_bot, cmdparams->source, "Can not find %s online\n", cmdparams->av[0]);
|
||||
return NS_ERR_SYNTAX_ERROR;
|
||||
}
|
||||
d = (unsigned char) (user->ip.s_addr >> 24) & 0xFF;
|
||||
c = (unsigned char) (user->ip.s_addr >> 16) & 0xFF;
|
||||
b = (unsigned char) (user->ip.s_addr >> 8) & 0xFF;
|
||||
a = (unsigned char) (user->ip.s_addr & 0xFF);
|
||||
c = (unsigned char) (user->ip.s_addr >> 16) & 0xFF;
|
||||
b = (unsigned char) (user->ip.s_addr >> 8) & 0xFF;
|
||||
a = (unsigned char) (user->ip.s_addr & 0xFF);
|
||||
|
||||
node = list_first(blsb.domains);
|
||||
while (node) {
|
||||
dl = lnode_get(node);
|
||||
buflen = 18 + strlen(dl->domain);
|
||||
sc = ns_malloc(sizeof(scanclient));
|
||||
sc->check = cmdparams->source;
|
||||
sc->user = user;
|
||||
sc->domain = dl;
|
||||
sc->lookup = ns_malloc(buflen);
|
||||
ircsnprintf(sc->lookup, buflen, "%d.%d.%d.%d.%s", d, c, b, a, dl->domain);
|
||||
switch (dl->type) {
|
||||
case 1: /* TXT record */
|
||||
dns_lookup(sc->lookup, adns_r_txt, dnsbl_callback, sc);
|
||||
break;
|
||||
node = list_first(blsb.domains);
|
||||
while (node) {
|
||||
dl = lnode_get(node);
|
||||
buflen = 18 + strlen(dl->domain);
|
||||
sc = ns_malloc(sizeof(scanclient));
|
||||
sc->check = cmdparams->source;
|
||||
sc->user = user;
|
||||
sc->domain = dl;
|
||||
sc->lookup = ns_malloc(buflen);
|
||||
ircsnprintf(sc->lookup, buflen, "%d.%d.%d.%d.%s", d, c, b, a, dl->domain);
|
||||
switch (dl->type) {
|
||||
case 1: /* TXT record */
|
||||
dns_lookup(sc->lookup, adns_r_txt, dnsbl_callback, sc);
|
||||
break;
|
||||
case 2: /* A record */
|
||||
dns_lookup(sc->lookup, adns_r_a, dnsbl_callback, sc);
|
||||
break;
|
||||
|
@ -268,7 +327,7 @@ int blsb_cmd_check (CmdParams* cmdparams)
|
|||
nlog(LOG_WARNING, "Unknown Type for DNS BL %s", dl->name);
|
||||
break;
|
||||
}
|
||||
node = list_next(blsb.domains, node);
|
||||
node = list_next(blsb.domains, node);
|
||||
}
|
||||
if (sc) {
|
||||
irc_prefmsg (blsb_bot, cmdparams->source, "Checking %s (%d.%d.%d.%d) against DNS Blacklists", sc->user->name, a, b, c, d);
|
||||
|
@ -277,28 +336,18 @@ int blsb_cmd_check (CmdParams* cmdparams)
|
|||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/** @brief ModSynch
|
||||
/** @brief dnsbl_callback
|
||||
*
|
||||
* Startup handler
|
||||
* DNS callback
|
||||
*
|
||||
* @param none
|
||||
* @param data
|
||||
* @param a
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else NS_FAILURE
|
||||
* @return NS_SUCCESS if suceeds else result of command
|
||||
*/
|
||||
|
||||
int ModSynch (void)
|
||||
void dnsbl_callback(void *data, adns_answer *a)
|
||||
{
|
||||
SET_SEGV_LOCATION();
|
||||
blsb_bot = AddBot (&blsb_botinfo);
|
||||
if( !blsb_bot )
|
||||
return NS_FAILURE;
|
||||
if( blsb.verbose )
|
||||
irc_chanalert (blsb_bot, "Black List Scanning bot has started");
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
void dnsbl_callback(void *data, adns_answer *a) {
|
||||
scanclient *sc = (scanclient *)data;
|
||||
int len, i, ri;
|
||||
char *show;
|
||||
|
@ -321,12 +370,19 @@ void dnsbl_callback(void *data, adns_answer *a) {
|
|||
if (sc->check) irc_prefmsg(blsb_bot, sc->check, "%s does not exist in %s blacklist", sc->user->name, sc->domain->name);
|
||||
dlog(DEBUG3, "No Record for %s", sc->lookup);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** @brief event_nickip
|
||||
*
|
||||
* NICKIP event handler
|
||||
* scan user that just signed on the network
|
||||
*
|
||||
* @cmdparams pointer to commands param struct
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else NS_FAILURE
|
||||
*/
|
||||
|
||||
/* this function kicks of a scan of a user that just signed on the network */
|
||||
static int ss_event_signon (CmdParams* cmdparams)
|
||||
static int event_nickip( CmdParams* cmdparams )
|
||||
{
|
||||
dom_list *dl;
|
||||
lnode_t *node;
|
||||
|
@ -336,13 +392,10 @@ static int ss_event_signon (CmdParams* cmdparams)
|
|||
|
||||
SET_SEGV_LOCATION();
|
||||
|
||||
if (ModIsServerExcluded(cmdparams->source->uplink)) {
|
||||
if (ModIsServerExcluded(cmdparams->source->uplink))
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
if (IsNetSplit(cmdparams->source)) {
|
||||
if (IsNetSplit(cmdparams->source))
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
d = (unsigned char) (cmdparams->source->ip.s_addr >> 24) & 0xFF;
|
||||
c = (unsigned char) (cmdparams->source->ip.s_addr >> 16) & 0xFF;
|
||||
|
@ -376,7 +429,18 @@ static int ss_event_signon (CmdParams* cmdparams)
|
|||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
int load_dom( void *data, int size) {
|
||||
/** @brief load_dom
|
||||
*
|
||||
* Database load domains row callback handler
|
||||
*
|
||||
* @param pointer to loaded data
|
||||
* @param size of loaded data
|
||||
*
|
||||
* @return NS_FALSE
|
||||
*/
|
||||
|
||||
static int load_dom( void *data, int size )
|
||||
{
|
||||
dom_list *dl;
|
||||
|
||||
dl = ns_calloc( sizeof(dom_list));
|
||||
|
@ -385,28 +449,102 @@ int load_dom( void *data, int size) {
|
|||
return NS_FALSE;
|
||||
}
|
||||
|
||||
/** @brief load_default_bldomains
|
||||
*
|
||||
* Load default domain settings
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
|
||||
static void load_default_bldomains( void )
|
||||
{
|
||||
dom_list *dl;
|
||||
dom_list *default_domains;
|
||||
|
||||
default_domains = stddomlist;
|
||||
while( default_domains->type != 0 )
|
||||
{
|
||||
dl = new_bldomain( default_domains->name, default_domains->domain, default_domains->type );
|
||||
default_domains++;
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief ModInit
|
||||
*
|
||||
* Init handler
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else NS_FAILURE
|
||||
*/
|
||||
|
||||
int ModInit( void )
|
||||
{
|
||||
int i;
|
||||
dom_list *dl;
|
||||
ModuleConfig (blsb_settings);
|
||||
blsb.domains = list_create(-1);
|
||||
DBAFetchRows("domains", load_dom);
|
||||
if (list_count(blsb.domains) == 0) {
|
||||
for (i = 0; stddomlist[i].type != 0; i++) {
|
||||
dl = ns_malloc(sizeof(dom_list));
|
||||
strlcpy(dl->name, stddomlist[i].name, BUFSIZE);
|
||||
strlcpy(dl->domain, stddomlist[i].domain, BUFSIZE);
|
||||
dl->type = stddomlist[i].type;
|
||||
/* Isn't this store pointless since we just loaded the entry anyway??? */
|
||||
DBAStore("domains", dl->name, (void *)dl, sizeof(dom_list));
|
||||
lnode_create_append(blsb.domains, dl);
|
||||
}
|
||||
ModuleConfig( blsb_settings );
|
||||
blsb.domains = list_create( -1 );
|
||||
if( !blsb.domains ) {
|
||||
nlog( LOG_CRITICAL, "Unable to create domain list" );
|
||||
return NS_FAILURE;
|
||||
}
|
||||
DBAFetchRows( "domains", load_dom );
|
||||
/* If no domains, this must be our first run so load defaults */
|
||||
if( list_count( blsb.domains ) == 0 )
|
||||
load_default_bldomains();
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
/** @brief ModSynch
|
||||
*
|
||||
* Startup handler
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else NS_FAILURE
|
||||
*/
|
||||
|
||||
int ModSynch (void)
|
||||
{
|
||||
SET_SEGV_LOCATION();
|
||||
blsb_bot = AddBot (&blsb_botinfo);
|
||||
if( !blsb_bot )
|
||||
return NS_FAILURE;
|
||||
if( blsb.verbose )
|
||||
irc_chanalert (blsb_bot, "Black List Scanning bot has started");
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
/** @brief ModFini
|
||||
*
|
||||
* Fini handler
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else NS_FAILURE
|
||||
*/
|
||||
|
||||
int ModFini( void )
|
||||
{
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
||||
/** @brief blsb_set_exclusions_cb
|
||||
*
|
||||
* Set callback for exclusions
|
||||
* Enable or disable exclude event flag
|
||||
*
|
||||
* @cmdparams pointer to commands param struct
|
||||
* @cmdparams reason for SET
|
||||
*
|
||||
* @return NS_SUCCESS if suceeds else NS_FAILURE
|
||||
*/
|
||||
|
||||
static int blsb_set_exclusions_cb( CmdParams *cmdparams, SET_REASON reason )
|
||||
{
|
||||
if( reason == SET_LOAD || reason == SET_CHANGE )
|
||||
{
|
||||
SetAllEventFlags( EVENT_FLAG_USE_EXCLUDE, blsb.exclusions );
|
||||
}
|
||||
return NS_SUCCESS;
|
||||
}
|
||||
|
|
30
blsb.h
30
blsb.h
|
@ -22,15 +22,14 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef blsb_H
|
||||
#define blsb_H
|
||||
#ifndef BLSB_H
|
||||
#define BLSB_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include "modconfigwin32.h"
|
||||
#else
|
||||
#else /* WIN32 */
|
||||
#include "modconfig.h"
|
||||
#endif
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
extern Bot *blsb_bot;
|
||||
|
||||
|
@ -65,21 +64,20 @@ typedef struct scanclient {
|
|||
char *lookup;
|
||||
} scanclient;
|
||||
|
||||
|
||||
/* blsb_help.c */
|
||||
extern const char *blsb_about[];
|
||||
extern const char blsb_help_add_oneline[];
|
||||
extern const char blsb_help_del_oneline[];
|
||||
extern const char blsb_help_list_oneline[];
|
||||
extern const char blsb_help_check_oneline[];
|
||||
extern const char *blsb_help_add[];
|
||||
extern const char *blsb_help_del[];
|
||||
extern const char *blsb_help_list[];
|
||||
extern const char *blsb_help_check[];
|
||||
extern const char *blsb_help_set_akill[];
|
||||
extern const char *blsb_help_set_akilltime[];
|
||||
extern const char *blsb_help_set_cachetime[];
|
||||
extern const char *blsb_help_set_verbose[];
|
||||
extern const char *blsb_help_set_exclusions[];
|
||||
extern const char blsb_help_domains_add_oneline[];
|
||||
extern const char blsb_help_domains_del_oneline[];
|
||||
extern const char blsb_help_domains_list_oneline[];
|
||||
extern const char *blsb_help_domains_add[];
|
||||
extern const char *blsb_help_domains_del[];
|
||||
extern const char *blsb_help_domains_list[];
|
||||
extern const char *blsb_about[];
|
||||
extern const char *blsb_help_check[];
|
||||
extern const char blsb_help_check_oneline[];
|
||||
|
||||
#endif /* blsb_H */
|
||||
#endif /* BLSB_H */
|
||||
|
|
70
blsb_help.c
70
blsb_help.c
|
@ -23,10 +23,10 @@
|
|||
|
||||
#include "neostats.h"
|
||||
|
||||
const char blsb_help_domains_add_oneline[] = "Add to the blacklist domains";
|
||||
const char blsb_help_domains_del_oneline[] = "Delete from the blacklist domains";
|
||||
const char blsb_help_domains_list_oneline[] = "List the blacklist domains";
|
||||
const char blsb_help_status_oneline[] = "View blsb state information";
|
||||
const char blsb_help_add_oneline[] = "Add to the blacklist domains";
|
||||
const char blsb_help_del_oneline[] = "Delete from the blacklist domains";
|
||||
const char blsb_help_list_oneline[] = "List the blacklist domains";
|
||||
const char blsb_help_status_oneline[] = "View blsb status";
|
||||
const char blsb_help_remove_oneline[] = "Remove an akill set by blsb";
|
||||
const char blsb_help_check_oneline[] = "Scan a selected user";
|
||||
|
||||
|
@ -61,6 +61,37 @@ const char *blsb_help_status[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_add[] = {
|
||||
"Syntax: \2ADD <NAME> <TYPE> <DOMAIN>\2",
|
||||
"",
|
||||
"\2ADD\2 will add a domain to the blacklist lookup list",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_del[] = {
|
||||
"Syntax: \2DEL <index>\2",
|
||||
"",
|
||||
"Delete entry <index> from the list of domains used for lookups",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_list[] = {
|
||||
"Syntax: \2LIST\2",
|
||||
"",
|
||||
"List the current domains used for lookups",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_remove[] = {
|
||||
"Syntax: \2REMOVE <ip|hostname>\2",
|
||||
"",
|
||||
"Remove akills that have been set by blsb.",
|
||||
"",
|
||||
"<ip|hostname> is the hostname listed in your akill list",
|
||||
"(usually found with /stats a)",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_set_akill [] = {
|
||||
"\2AKILL <ON|OFF>\2",
|
||||
"Whether to issue an akill for positive lookups",
|
||||
|
@ -90,34 +121,3 @@ const char *blsb_help_set_exclusions[] = {
|
|||
"Use global exclusion list in addition to local exclusion list",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_domains_add[] = {
|
||||
"Syntax: \2ADD <NAME> <TYPE> <DOMAIN>\2",
|
||||
"",
|
||||
"\2ADD\2 will add a domain to the blacklist lookup list",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_domains_del[] = {
|
||||
"Syntax: \2DEL <index>\2",
|
||||
"",
|
||||
"Delete entry <index> from the list of domains used for lookups",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_domains_list[] = {
|
||||
"Syntax: \2LIST\2",
|
||||
"",
|
||||
"List the current domains used for lookups",
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *blsb_help_remove[] = {
|
||||
"Syntax: \2REMOVE <ip|hostname>\2",
|
||||
"",
|
||||
"Remove akills that have been set by blsb.",
|
||||
"",
|
||||
"<ip|hostname> is the hostname listed in your akill list",
|
||||
"(usually found with /stats a)",
|
||||
NULL
|
||||
};
|
||||
|
|
Reference in a new issue