Restrict connections to localhost
This commit is contained in:
parent
2e65ae85eb
commit
c5bb663cad
22
src/server.d
22
src/server.d
|
@ -121,12 +121,23 @@ int main(string[] args)
|
||||||
// No relative paths
|
// No relative paths
|
||||||
version (Posix) chdir("/");
|
version (Posix) chdir("/");
|
||||||
|
|
||||||
|
version (LittleEndian)
|
||||||
|
immutable expectedClient = IPv4Union([127, 0, 0, 1]);
|
||||||
|
else
|
||||||
|
immutable expectedClient = IPv4Union([1, 0, 0, 127]);
|
||||||
|
|
||||||
serverLoop: while (true)
|
serverLoop: while (true)
|
||||||
{
|
{
|
||||||
auto s = socket.accept();
|
auto s = socket.accept();
|
||||||
s.blocking = true;
|
s.blocking = true;
|
||||||
|
|
||||||
// TODO: Restrict connections to localhost
|
// Only accept connections from localhost
|
||||||
|
IPv4Union actual;
|
||||||
|
InternetAddress clientAddr = cast(InternetAddress) s.remoteAddress();
|
||||||
|
actual.i = clientAddr.addr;
|
||||||
|
// Shut down if somebody tries connecting from outside
|
||||||
|
enforce(actual.i = expectedClient.i, "Connection attempted from "
|
||||||
|
~ clientAddr.toAddrString());
|
||||||
|
|
||||||
scope (exit)
|
scope (exit)
|
||||||
{
|
{
|
||||||
|
@ -253,6 +264,15 @@ string getConfigurationLocation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// IP v4 address as bytes and a uint
|
||||||
|
union IPv4Union
|
||||||
|
{
|
||||||
|
/// the bytes
|
||||||
|
ubyte[4] b;
|
||||||
|
/// the uint
|
||||||
|
uint i;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a warning message to the user when an old config file is detected.
|
* Prints a warning message to the user when an old config file is detected.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue