aboutsummaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2019-07-16 15:11:21 +0100
committerGravatar Sadie Powell2019-07-16 16:48:18 +0100
commitcd8b456f979733525941284639d8bf899173b429 (patch)
treef1d26962e61c74c5acb076662a909beafbe8e5fd /src/socket.cpp
parentReplace socketengine_{pthread,win32} with C++11 threads. (diff)
parentssl_gnutls: remove PackageInfo directives for EOL Debian versions. (diff)
Merge branch 'insp3' into master.
Diffstat (limited to 'src/socket.cpp')
-rw-r--r--src/socket.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/socket.cpp b/src/socket.cpp
index ecddba293..04deac089 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -98,24 +98,31 @@ int InspIRCd::BindPorts(FailedPortList& failed_ports)
const std::string path = tag->getString("path");
if (!path.empty())
{
+ // Expand the path relative to the config directory.
+ const std::string fullpath = ServerInstance->Config->Paths.PrependData(path);
+
// UNIX socket paths are length limited to less than PATH_MAX.
irc::sockets::sockaddrs bindspec;
- if (path.length() > std::min(ServerInstance->Config->Limits.MaxHost, sizeof(bindspec.un.sun_path) - 1))
+ if (fullpath.length() > std::min(ServerInstance->Config->Limits.MaxHost, sizeof(bindspec.un.sun_path) - 1))
{
this->Logs.Log("SOCKET", LOG_DEFAULT, "UNIX listener on %s at %s specified a path that is too long!",
- path.c_str(), tag->getTagLocation().c_str());
+ fullpath.c_str(), tag->getTagLocation().c_str());
continue;
}
// Check for characters which are problematic in the IRC message format.
- if (path.find_first_of("\n\r\t!@: ") != std::string::npos)
+ if (fullpath.find_first_of("\n\r\t!@: ") != std::string::npos)
{
this->Logs.Log("SOCKET", LOG_DEFAULT, "UNIX listener on %s at %s specified a path containing invalid characters!",
- path.c_str(), tag->getTagLocation().c_str());
+ fullpath.c_str(), tag->getTagLocation().c_str());
continue;
}
- irc::sockets::untosa(path, bindspec);
+ const bool replace = tag->getBool("replace");
+ if (replace && irc::sockets::isunix(fullpath))
+ remove(fullpath.c_str());
+
+ irc::sockets::untosa(fullpath, bindspec);
if (!BindPort(tag, bindspec, old_ports))
failed_ports.push_back(std::make_pair(bindspec, errno));
else
@@ -189,6 +196,17 @@ bool irc::sockets::untosa(const std::string& path, irc::sockets::sockaddrs& sa)
return true;
}
+bool irc::sockets::isunix(const std::string& file)
+{
+#ifndef _WIN32
+ struct stat sb;
+ if (stat(file.c_str(), &sb) == 0 && S_ISSOCK(sb.st_mode))
+ return true;
+#endif
+ return false;
+}
+
+
int irc::sockets::sockaddrs::family() const
{
return sa.sa_family;