Commit 3c8ca7e3 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Add support for IP blocking/filtering via file (ala SBBS ip.can)

svdm.ini IpFilterFile can be set to the path/filename of an "ip filter file",
list of IP addresses or patterns (CIDRv4 notation supported) to refuse
connections from.

This is reusing the same IP filter file logic from SBBS, so the same filter
file syntax/rules apply.
parent ab157c66
Pipeline #3077 passed with stage
in 10 minutes and 19 seconds
......@@ -29,6 +29,7 @@
#include <process.h>
#include "genwrap.h"
#include "findstr.h"
#include "dirwrap.h"
#include "gen_defs.h"
#include "sockwrap.h"
......@@ -77,6 +78,7 @@ struct {
ulong data_rate;
bool server_echo;
char client_file[MAX_PATH + 1];
char ip_filter_file[MAX_PATH + 1];
char busy_notice[INI_MAX_VALUE_LEN];
char answer_banner[INI_MAX_VALUE_LEN];
enum {
......@@ -1007,9 +1009,16 @@ void listen_thread(void* arg)
SOCKET newsock = accept(listening_sock, (SOCKADDR*)&newaddr, &addrlen);
if(newsock == INVALID_SOCKET)
continue;
char tmp[256];
char ipaddr[256];
inet_addrtop(&newaddr, ipaddr, sizeof(ipaddr));
dprintf("Connection accepted from TCP port %hu at %s"
,inet_addrport(&newaddr), inet_addrtop(&newaddr, tmp, sizeof(tmp)));
,inet_addrport(&newaddr), ipaddr);
if(findstr(ipaddr, cfg.ip_filter_file)) {
dprintf("IP address blocked: %s", ipaddr);
shutdown(newsock, SD_SEND);
closesocket(newsock);
continue;
}
if(sock != INVALID_SOCKET) { // In-use
send(newsock, cfg.busy_notice, strlen(cfg.busy_notice), /* flags: */0);
shutdown(newsock, SD_SEND);
......@@ -1051,6 +1060,8 @@ bool read_ini(const char* ini_fname)
SAFECOPY(cfg.answer_banner, p);
if((p = iniGetString(ini, ROOT_SECTION, "ClientFile", NULL, value)) != NULL)
SAFECOPY(cfg.client_file, p);
if((p = iniGetString(ini, ROOT_SECTION, "IpFilterFile", NULL, value)) != NULL)
SAFECOPY(cfg.ip_filter_file, p);
return true;
}
......
......@@ -98,9 +98,9 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);TELNET_NO_DLL</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);TELNET_NO_DLL;SBBS_EXPORTS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../sbbs3/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../sbbs3/;../encode/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
......@@ -116,9 +116,9 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);TELNET_NO_DLL</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);TELNET_NO_DLL;SBBS_EXPORTS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../sbbs3/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../sbbs3/;../encode/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
......@@ -136,7 +136,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);TELNET_NO_DLL</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../sbbs3/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../sbbs3/;../encode/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
......@@ -154,7 +154,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);TELNET_NO_DLL</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../sbbs3/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../sbbs3/;../encode/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
......@@ -167,6 +167,9 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\encode\utf8.c" />
<ClCompile Include="..\sbbs3\findstr.c" />
<ClCompile Include="..\sbbs3\str_util.c" />
<ClCompile Include="..\sbbs3\telnet.c" />
<ClCompile Include="vdmodem.c" />
</ItemGroup>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment