X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsocket.cpp;h=f19af36bb48a9728d2fd49c372e4cfd8c1129860;hb=5a2af6ded883d71c6c4c9f1497cca1721f8b0742;hp=1d110323567a589ca39d3a55c89a2c1884363540;hpb=b7716ed57704b2b2bcc665a590aecc8f02de631d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/socket.cpp b/src/socket.cpp index 1d1103235..f19af36bb 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -39,7 +39,7 @@ bool InspIRCd::BindPort(ConfigTag* tag, const irc::sockets::sockaddrs& sa, std:: return true; } } - + ListenSocket* ll = new ListenSocket(tag, sa); if (ll->GetFd() < 0) { @@ -93,29 +93,38 @@ int InspIRCd::BindPorts(FailedPortList& failed_ports) continue; } +#ifndef _WIN32 // Are we creating a UNIX listener? 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))) + 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; } - // Create the bindspec manually (aptosa doesn't work with AF_UNIX yet). - memset(&bindspec, 0, sizeof(bindspec)); - bindspec.un.sun_family = AF_UNIX; - stpncpy(bindspec.un.sun_path, path.c_str(), sizeof(bindspec.un.sun_path) - 1); + // Check for characters which are problematic in the IRC message format. + 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!", + fullpath.c_str(), tag->getTagLocation().c_str()); + continue; + } + irc::sockets::untosa(fullpath, bindspec); if (!BindPort(tag, bindspec, old_ports)) failed_ports.push_back(std::make_pair(bindspec, errno)); else bound++; } +#endif } std::vector::iterator n = ports.begin(); @@ -172,6 +181,28 @@ bool irc::sockets::aptosa(const std::string& addr, int port, irc::sockets::socka return false; } +bool irc::sockets::untosa(const std::string& path, irc::sockets::sockaddrs& sa) +{ + memset(&sa, 0, sizeof(sa)); + if (path.length() >= sizeof(sa.un.sun_path)) + return false; + + sa.un.sun_family = AF_UNIX; + memcpy(&sa.un.sun_path, path.c_str(), path.length() + 1); + 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; @@ -352,7 +383,7 @@ irc::sockets::cidr_mask::cidr_mask(const std::string& mask) } else { - int range = ConvToInt(mask.substr(bits_chars + 1)); + unsigned char range = ConvToNum(mask.substr(bits_chars + 1)); irc::sockets::aptosa(mask.substr(0, bits_chars), 0, sa); sa2cidr(*this, sa, range); } @@ -375,6 +406,7 @@ std::string irc::sockets::cidr_mask::str() const case AF_INET6: base = (unsigned char*)&sa.in6.sin6_addr; len = 16; + break; case AF_UNIX: return sa.un.sun_path; @@ -386,7 +418,7 @@ std::string irc::sockets::cidr_mask::str() const } memcpy(base, bits, len); - return sa.addr() + "/" + ConvToStr(length); + return sa.addr() + "/" + ConvToStr((int)length); } bool irc::sockets::cidr_mask::operator==(const cidr_mask& other) const