mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-01 15:46:37 +02:00
3-2beta13
This commit is contained in:
+196
-129
@@ -60,11 +60,23 @@ int Scan_BanTime = 0, Scan_TimeOut = 0;
|
||||
static Scan_AddrStruct *Scannings = NULL;
|
||||
MUTEX Scannings_lock;
|
||||
static char *scan_message;
|
||||
|
||||
extern ConfigEntry *config_find_entry(ConfigEntry *ce, char *name);
|
||||
DLLFUNC int h_scan_connect(aClient *sptr);
|
||||
DLLFUNC int h_config_set_scan(void);
|
||||
DLLFUNC int h_config_test(ConfigFile *, ConfigEntry *, int, int *);
|
||||
DLLFUNC int h_config_run(ConfigFile *, ConfigEntry *, int);
|
||||
DLLFUNC int h_config_posttest(int *);
|
||||
DLLFUNC int h_config_rehash();
|
||||
DLLFUNC int h_stats_scan(aClient *sptr, char *stats);
|
||||
|
||||
struct requiredconfig {
|
||||
int endpoint :1;
|
||||
int timeout :1;
|
||||
int bantime :1;
|
||||
int bindip :1;
|
||||
};
|
||||
|
||||
struct requiredconfig ReqConf;
|
||||
|
||||
#ifndef DYNAMIC_LINKING
|
||||
ModuleHeader m_scan_Header
|
||||
#else
|
||||
@@ -82,10 +94,24 @@ ModuleHeader Mod_Header
|
||||
EVENT(e_scannings_clean);
|
||||
|
||||
static Event *Scannings_clean = NULL;
|
||||
static Hook *LocConnect = NULL, *ConfUnknown = NULL, *ServerStats = NULL;
|
||||
static Hook *LocConnect = NULL, *ConfTest = NULL, *ConfRun = NULL, *ServerStats = NULL;
|
||||
static Hook *ConfPostTest = NULL, *ConfRehash = NULL;
|
||||
static Hooktype *ScanHost = NULL;
|
||||
static int HOOKTYPE_SCAN_HOST;
|
||||
ModuleInfo ScanModInfo;
|
||||
|
||||
#ifdef DYNAMIC_LINKING
|
||||
DLLFUNC int Mod_Test(ModuleInfo *modinfo)
|
||||
#else
|
||||
int m_scan_Test(ModuleInfo *modinfo)
|
||||
#endif
|
||||
{
|
||||
bcopy(modinfo,&ScanModInfo,modinfo->size);
|
||||
ConfTest = HookAddEx(ScanModInfo.handle, HOOKTYPE_CONFIGTEST, h_config_test);
|
||||
ConfPostTest = HookAddEx(ScanModInfo.handle, HOOKTYPE_CONFIGPOSTTEST, h_config_posttest);
|
||||
return MOD_SUCCESS;
|
||||
}
|
||||
|
||||
/* This is called on module init, before Server Ready */
|
||||
#ifdef DYNAMIC_LINKING
|
||||
DLLFUNC int Mod_Init(ModuleInfo *modinfo)
|
||||
@@ -93,12 +119,13 @@ DLLFUNC int Mod_Init(ModuleInfo *modinfo)
|
||||
int m_scan_Init(ModuleInfo *modinfo)
|
||||
#endif
|
||||
{
|
||||
int id;
|
||||
scan_message = NULL;
|
||||
bcopy(modinfo,&ScanModInfo,modinfo->size);
|
||||
bzero(&ReqConf, sizeof(ReqConf));
|
||||
ScanHost = (Hooktype *)HooktypeAdd(modinfo->handle, "HOOKTYPE_SCAN_HOST", &HOOKTYPE_SCAN_HOST);
|
||||
LocConnect = HookAddEx(ScanModInfo.handle, HOOKTYPE_LOCAL_CONNECT, h_scan_connect);
|
||||
ConfUnknown = HookAddEx(ScanModInfo.handle, HOOKTYPE_CONFIG_UNKNOWN, h_config_set_scan);
|
||||
ConfRun = HookAddEx(ScanModInfo.handle, HOOKTYPE_CONFIGRUN, h_config_run);
|
||||
ConfRehash = HookAddEx(ScanModInfo.handle, HOOKTYPE_REHASH, h_config_rehash);
|
||||
ServerStats = HookAddEx(ScanModInfo.handle, HOOKTYPE_STATS, h_stats_scan);
|
||||
bzero(&Scan_bind, sizeof(Scan_bind));
|
||||
IRCCreateMutex(Scannings_lock);
|
||||
@@ -112,36 +139,6 @@ DLLFUNC int Mod_Load(int module_load)
|
||||
int m_scan_Load(int module_load)
|
||||
#endif
|
||||
{
|
||||
if (Scan_endpoint.SIN_PORT == 0)
|
||||
{
|
||||
|
||||
if (*conf_listen->ip == '*') {
|
||||
ircd_log(LOG_ERROR, "Scan.so failed to load: set::scan::endpoint is missing");
|
||||
HooktypeDel(ScanHost,ScanModInfo.handle);
|
||||
HookDel(LocConnect);
|
||||
HookDel(ConfUnknown);
|
||||
HookDel(ServerStats);
|
||||
LockEventSystem();
|
||||
EventDel(Scannings_clean);
|
||||
UnlockEventSystem();
|
||||
IRCMutexDestroy(Scannings_lock);
|
||||
return MOD_FAILED;
|
||||
}
|
||||
|
||||
#ifndef INET6
|
||||
Scan_endpoint.SIN_ADDR.S_ADDR = inet_addr(conf_listen->ip);
|
||||
#else
|
||||
inet_pton(AFINET, conf_listen->ip, Scan_endpoint.SIN_ADDR.S_ADDR);
|
||||
#endif
|
||||
Scan_endpoint.SIN_PORT = htons(conf_listen->port);
|
||||
Scan_endpoint.SIN_FAMILY = AFINET;
|
||||
}
|
||||
|
||||
if (Scan_BanTime == 0)
|
||||
Scan_BanTime = 86400;
|
||||
|
||||
if (Scan_TimeOut == 0)
|
||||
Scan_TimeOut = 20;
|
||||
LockEventSystem();
|
||||
Scannings_clean = EventAddEx(ScanModInfo.handle, "e_scannings_clean", 0, 0, e_scannings_clean, NULL);
|
||||
UnlockEventSystem();
|
||||
@@ -175,7 +172,9 @@ int m_scan_Unload(void)
|
||||
{
|
||||
HooktypeDel(ScanHost,ScanModInfo.handle);
|
||||
HookDel(LocConnect);
|
||||
HookDel(ConfUnknown);
|
||||
HookDel(ConfTest);
|
||||
HookDel(ConfRun);
|
||||
HookDel(ConfPostTest);
|
||||
HookDel(ServerStats);
|
||||
LockEventSystem();
|
||||
EventDel(Scannings_clean);
|
||||
@@ -348,108 +347,176 @@ DLLFUNC int h_scan_connect(aClient *sptr)
|
||||
* };
|
||||
*
|
||||
*/
|
||||
DLLFUNC h_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) {
|
||||
ConfigEntry *cep;
|
||||
int errors = 0;
|
||||
|
||||
DLLFUNC int h_config_set_scan(void)
|
||||
{
|
||||
ConfigItem_unknown_ext *sets;
|
||||
ConfigEntry *ce;
|
||||
char *ip;
|
||||
char *port;
|
||||
int iport;
|
||||
for (sets = conf_unknown_set; sets;
|
||||
sets = (ConfigItem_unknown_ext *)sets->next)
|
||||
if (type != CONFIG_SET)
|
||||
return 0;
|
||||
|
||||
if (!strcmp(ce->ce_varname, "scan"))
|
||||
{
|
||||
if (!strcmp(sets->ce_varname, "scan"))
|
||||
for (cep = ce->ce_entries; cep; cep = cep->ce_next)
|
||||
{
|
||||
for (ce = sets->ce_entries; ce; ce = (ConfigEntry *)ce->ce_next)
|
||||
if (!cep->ce_varname)
|
||||
{
|
||||
if (!strcmp(ce->ce_varname, "bantime")) {
|
||||
if (!ce->ce_vardata) {
|
||||
config_status("%s:%i: set::scan::bantime has no value",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
break;
|
||||
}
|
||||
Scan_BanTime = config_checkval(ce->ce_vardata,CFG_TIME);
|
||||
}
|
||||
else
|
||||
if (!strcmp(ce->ce_varname, "timeout")) {
|
||||
if (!ce->ce_vardata) {
|
||||
config_status("%s:%i: set::scan::timeout has no value",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
break;
|
||||
}
|
||||
Scan_TimeOut = config_checkval(ce->ce_vardata,CFG_TIME);
|
||||
}
|
||||
else
|
||||
if (!strcmp(ce->ce_varname, "endpoint"))
|
||||
{
|
||||
if (!ce->ce_vardata)
|
||||
{
|
||||
config_status("%s:%i: set::scan::endpoint: syntax [ip]:port",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
break;
|
||||
}
|
||||
ipport_seperate(ce->ce_vardata, &ip, &port);
|
||||
if (!ip || !*ip)
|
||||
{
|
||||
config_status("%s:%i: set::scan::endpoint: illegal ip",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
break;
|
||||
}
|
||||
if (!port || !*port)
|
||||
{
|
||||
config_status("%s:%i: set::scan::endpoint: missing/invalid port",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
break;
|
||||
}
|
||||
iport = atol(port);
|
||||
if ((iport < 0) || (iport > 65535))
|
||||
{
|
||||
config_status("%s:%i: set::scan::endpoint: illegal port",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
break;
|
||||
}
|
||||
#ifndef INET6
|
||||
Scan_endpoint.SIN_ADDR.S_ADDR = inet_addr(ip);
|
||||
#else
|
||||
inet_pton(AFINET, ip, Scan_endpoint.SIN_ADDR.S_ADDR);
|
||||
#endif
|
||||
Scan_endpoint.SIN_PORT = htons(iport);
|
||||
Scan_endpoint.SIN_FAMILY = AFINET;
|
||||
}
|
||||
else if (!strcmp(ce->ce_varname, "bind-ip"))
|
||||
{
|
||||
if (!ce->ce_vardata)
|
||||
{
|
||||
config_status("%s:%i: set::scan::bind: syntax [ip]",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
break;
|
||||
}
|
||||
#ifndef INET6
|
||||
Scan_bind.S_ADDR = inet_addr(ce->ce_vardata);
|
||||
#else
|
||||
inet_pton(AFINET, ce->ce_vardata, Scan_bind.S_ADDR);
|
||||
#endif
|
||||
}
|
||||
else if (!strcmp(ce->ce_varname, "message"))
|
||||
{
|
||||
if (!ce->ce_vardata)
|
||||
{
|
||||
config_status("%s:%i: set::scan::message requires an argument",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
break;
|
||||
}
|
||||
if (scan_message)
|
||||
free(scan_message);
|
||||
scan_message = strdup(ce->ce_vardata);
|
||||
}
|
||||
config_error("%s:%i: blank set::scan item",
|
||||
cep->ce_fileptr->cf_filename,
|
||||
cep->ce_varlinenum);
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
del_ConfigItem(sets, conf_unknown_set);
|
||||
}
|
||||
if (!cep->ce_vardata)
|
||||
{
|
||||
config_error("%s:%i: set::scan::%s item without value",
|
||||
cep->ce_fileptr->cf_filename,
|
||||
cep->ce_varlinenum, cep->ce_varname);
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(cep->ce_varname, "endpoint"))
|
||||
{
|
||||
char copy[256];
|
||||
char *ip, *port;
|
||||
int iport;
|
||||
strcpy(copy, cep->ce_vardata);
|
||||
ipport_seperate(copy, &ip, &port);
|
||||
if (!ip || !*ip)
|
||||
{
|
||||
config_error("%s:%i: set::scan::endpoint: illegal ip:port mask",
|
||||
cep->ce_fileptr->cf_filename, cep->ce_varlinenum);
|
||||
errors++;
|
||||
}
|
||||
if (strchr(ip, '*'))
|
||||
{
|
||||
config_error("%s:%i: set::scan::endpoint: illegal ip",
|
||||
cep->ce_fileptr->cf_filename, cep->ce_varlinenum);
|
||||
errors++;
|
||||
}
|
||||
if (!port || !*port)
|
||||
{
|
||||
config_error("%s:%i: set::scan::endpoint: missing port in mask",
|
||||
cep->ce_fileptr->cf_filename, cep->ce_varlinenum);
|
||||
errors++;
|
||||
}
|
||||
iport = atol(port);
|
||||
if ((iport < 0) || (iport > 65535))
|
||||
{
|
||||
config_error("%s:%i: set::scan::endpoint: illegal port (must be 0..65536)",
|
||||
cep->ce_fileptr->cf_filename, cep->ce_varlinenum);
|
||||
errors++;
|
||||
}
|
||||
ReqConf.endpoint = 1;
|
||||
}
|
||||
else if (!strcmp(cep->ce_varname, "bind-ip"))
|
||||
{
|
||||
if (strchr(cep->ce_vardata, '*') && strcmp(cep->ce_vardata, "*"))
|
||||
{
|
||||
config_error("%s:%i: set::scan::bind-ip: illegal ip, (mask, and not '*')",
|
||||
ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
|
||||
errors++;
|
||||
}
|
||||
ReqConf.bindip = 1;
|
||||
}
|
||||
else if (!strcmp(cep->ce_varname, "message"));
|
||||
else if (!strcmp(cep->ce_varname, "bantime"))
|
||||
ReqConf.bantime = 1;
|
||||
else if (!strcmp(cep->ce_varname, "timeout"))
|
||||
ReqConf.timeout = 1;
|
||||
else
|
||||
{
|
||||
config_error("%s:%i: unknown directive set::scan::%s",
|
||||
cep->ce_fileptr->cf_filename, cep->ce_varlinenum,
|
||||
cep->ce_varname);
|
||||
errors++;
|
||||
}
|
||||
|
||||
}
|
||||
*errs = errors;
|
||||
return errors ? -1 : 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
DLLFUNC h_config_run(ConfigFile *cf, ConfigEntry *ce, int type) {
|
||||
ConfigEntry *cep;
|
||||
int errors = 0;
|
||||
|
||||
if (type != CONFIG_SET)
|
||||
return 0;
|
||||
if (!strcmp(ce->ce_varname, "scan"))
|
||||
{
|
||||
for (cep = ce->ce_entries; cep; cep = cep->ce_next)
|
||||
{
|
||||
if (!strcmp(cep->ce_varname, "endpoint"))
|
||||
{
|
||||
char copy[256];
|
||||
char *ip, *port;
|
||||
int iport;
|
||||
strcpy(copy, cep->ce_vardata);
|
||||
ipport_seperate(copy, &ip, &port);
|
||||
#ifndef INET6
|
||||
Scan_endpoint.SIN_ADDR.S_ADDR = inet_addr(ip);
|
||||
#else
|
||||
inet_pton(AFINET, ip, Scan_endpoint.SIN_ADDR.S_ADDR);
|
||||
#endif
|
||||
iport = atol(port);
|
||||
Scan_endpoint.SIN_PORT = htons(iport);
|
||||
Scan_endpoint.SIN_FAMILY = AFINET;
|
||||
}
|
||||
else if (!strcmp(cep->ce_varname, "bantime"))
|
||||
Scan_BanTime = config_checkval(cep->ce_vardata,CFG_TIME);
|
||||
else if (!strcmp(cep->ce_varname, "timeout"))
|
||||
Scan_TimeOut = config_checkval(cep->ce_vardata,CFG_TIME);
|
||||
else if (!strcmp(cep->ce_varname, "bind-ip"))
|
||||
{
|
||||
#ifndef INET6
|
||||
Scan_bind.S_ADDR = inet_addr(cep->ce_vardata);
|
||||
#else
|
||||
inet_pton(AFINET, cep->ce_vardata, Scan_bind.S_ADDR);
|
||||
#endif
|
||||
}
|
||||
if (!strcmp(cep->ce_varname, "message"))
|
||||
scan_message = strdup(cep->ce_vardata);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
DLLFUNC int h_config_posttest(int *errs) {
|
||||
int errors = 0;
|
||||
if (!ReqConf.endpoint)
|
||||
{
|
||||
config_error("set::scan::endpoint missing");
|
||||
errors++;
|
||||
}
|
||||
if (!ReqConf.bantime)
|
||||
{
|
||||
config_error("set::scan::bantime missing");
|
||||
errors++;
|
||||
}
|
||||
if (!ReqConf.timeout)
|
||||
{
|
||||
config_error("set::scan::timeout missing");
|
||||
errors++;
|
||||
}
|
||||
if (!ReqConf.bindip)
|
||||
{
|
||||
config_error("set::scan::bind-ip missing");
|
||||
errors++;
|
||||
}
|
||||
*errs = errors;
|
||||
return errors ? -1 : 1;
|
||||
}
|
||||
|
||||
DLLFUNC int h_config_rehash()
|
||||
{
|
||||
if (scan_message)
|
||||
MyFree(scan_message);
|
||||
}
|
||||
|
||||
DLLFUNC int h_stats_scan(aClient *sptr, char *stats) {
|
||||
if (*stats == 'S') {
|
||||
sendto_one(sptr, ":%s %i %s :scan::endpoint: %s:%d", me.name, RPL_TEXT, sptr->name,
|
||||
|
||||
Reference in New Issue
Block a user