summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules.h2
-rw-r--r--include/usermanager.h2
-rw-r--r--src/modules.cpp2
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp54
-rw-r--r--src/socket.cpp23
-rw-r--r--src/usermanager.cpp10
6 files changed, 49 insertions, 44 deletions
diff --git a/include/modules.h b/include/modules.h
index de0e0d7fe..48d063455 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -1245,7 +1245,7 @@ class CoreExport Module : public Extensible
*/
virtual int OnDelBan(User* source, Channel* channel,const std::string &banmask);
- virtual void OnHookUserIO(User* user);
+ virtual void OnHookUserIO(User* user, const std::string &targetip);
/** Called immediately after any connection is accepted. This is intended for raw socket
* processing (e.g. modules which wrap the tcp connection within another library) and provides
diff --git a/include/usermanager.h b/include/usermanager.h
index 0fe418ba3..6016a2462 100644
--- a/include/usermanager.h
+++ b/include/usermanager.h
@@ -71,7 +71,7 @@ class CoreExport UserManager : public classbase
* @param ip The IP address of the user
* @return This function has no return value, but a call to AddClient may remove the user.
*/
- void AddClient(InspIRCd* Instance, int socket, int port, bool iscached, int socketfamily, sockaddr* ip);
+ void AddClient(InspIRCd* Instance, int socket, int port, bool iscached, int socketfamily, sockaddr* ip, const std::string &targetip);
/** Add a user to the local clone map
* @param user The user to add
diff --git a/src/modules.cpp b/src/modules.cpp
index 82dbea185..5ec74da7b 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -195,7 +195,7 @@ void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
void Module::OnRunTestSuite() { }
void Module::OnNamesListItem(User*, User*, Channel*, std::string&, std::string&) { }
int Module::OnNumeric(User*, unsigned int, const std::string&) { return 0; }
-void Module::OnHookUserIO(User*) { }
+void Module::OnHookUserIO(User*, const std::string&) { }
ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
{
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index f3af386ae..7b4b68694 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -41,13 +41,9 @@
enum issl_status { ISSL_NONE, ISSL_HANDSHAKING_READ, ISSL_HANDSHAKING_WRITE, ISSL_HANDSHAKEN, ISSL_CLOSING, ISSL_CLOSED };
-bool isin(int port, const std::vector<int> &portlist)
+bool isin(std::string hostandport, const std::vector<std::string> &portlist)
{
- for(unsigned int i = 0; i < portlist.size(); i++)
- if(portlist[i] == port)
- return true;
-
- return false;
+ return std::find(portlist.begin(), portlist.end(), hostandport) != portlist.end();
}
/** Represents an SSL user's extra data
@@ -79,7 +75,7 @@ class CommandStartTLS : public Command
return CMD_FAILURE;
user->io = Caller;
- Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), ServerInstance->Config->ports[i]->GetPort());
+ Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), user->GetPort());
return CMD_FAILURE;
}
@@ -92,7 +88,7 @@ class ModuleSSLGnuTLS : public Module
char* dummy;
- std::vector<int> listenports;
+ std::vector<std::string> listenports;
int inbufsize;
issl_session sessions[MAX_DESCRIPTORS];
@@ -147,11 +143,6 @@ class ModuleSSLGnuTLS : public Module
{
Conf = new ConfigReader(ServerInstance);
- for(unsigned int i = 0; i < listenports.size(); i++)
- {
- ServerInstance->Config->DelIOHook(listenports[i]);
- }
-
listenports.clear();
clientactive = 0;
sslports.clear();
@@ -164,6 +155,8 @@ class ModuleSSLGnuTLS : public Module
{
// Get the port we're meant to be listening on with SSL
std::string port = Conf->ReadValue("bind", "port", index);
+ std::string addr = Conf->ReadValue("bind", "address", index);
+
irc::portparser portrange(port, false);
long portno = -1;
while ((portno = portrange.GetToken()))
@@ -171,19 +164,14 @@ class ModuleSSLGnuTLS : public Module
clientactive++;
try
{
- if (ServerInstance->Config->AddIOHook(portno, this))
- {
- listenports.push_back(portno);
- for (size_t i = 0; i < ServerInstance->Config->ports.size(); i++)
- if (ServerInstance->Config->ports[i]->GetPort() == portno)
- ServerInstance->Config->ports[i]->SetDescription("ssl");
- ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %d", portno);
- sslports.append("*:").append(ConvToStr(portno)).append(";");
- }
- else
- {
- ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: FAILED to enable SSL on port %d, maybe you have another ssl or similar module loaded?", portno);
- }
+ listenports.push_back(addr + ":" + ConvToStr(portno));
+
+ for (size_t i = 0; i < ServerInstance->Config->ports.size(); i++)
+ if ((ServerInstance->Config->ports[i]->GetPort() == portno) && (ServerInstance->Config->ports[i]->GetIP() == addr))
+ ServerInstance->Config->ports[i]->SetDescription("ssl");
+ ServerInstance->Logs->Log("m_ssl_gnutls",DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %d", portno);
+
+ sslports.append((addr.empty() ? "*" : addr)).append(":").append(ConvToStr(portno)).append(";");
}
catch (ModuleException &e)
{
@@ -284,13 +272,13 @@ class ModuleSSLGnuTLS : public Module
{
User* user = (User*)item;
- if(user->GetExt("ssl", dummy) && isin(user->GetPort(), listenports))
+ if(user->io)
{
// User is using SSL, they're a local user, and they're using one of *our* SSL ports.
// Potentially there could be multiple SSL modules loaded at once on different ports.
User::QuitUser(ServerInstance, user, "SSL module unloading");
}
- if (user->GetExt("ssl_cert", dummy) && isin(user->GetPort(), listenports))
+ if (user->GetExt("ssl_cert", dummy))
{
ssl_cert* tofree;
user->GetExt("ssl_cert", tofree);
@@ -308,9 +296,8 @@ class ModuleSSLGnuTLS : public Module
{
for(unsigned int i = 0; i < listenports.size(); i++)
{
- ServerInstance->Config->DelIOHook(listenports[i]);
for (size_t j = 0; j < ServerInstance->Config->ports.size(); j++)
- if (ServerInstance->Config->ports[j]->GetPort() == listenports[i])
+ if (listenports[i] == (ServerInstance->Config->ports[j]->GetIP()+":"+ConvToStr(ServerInstance->Config->ports[j]->GetPort())))
ServerInstance->Config->ports[j]->SetDescription("plaintext");
}
}
@@ -327,9 +314,10 @@ class ModuleSSLGnuTLS : public Module
output.append(" SSL=" + sslports);
}
- virtual void OnHookUserIO(User* user)
+ virtual void OnHookUserIO(User* user, const std::string &targetip)
{
- if (!user->io && isin(user->GetPort(), listenports))
+ ServerInstance->Logs->Log("m_ssl_gnutls", DEBUG, "*** OnHookUserIO, target IP = %s", targetip.c_str());
+ if (!user->io && isin(targetip+":"+ConvToStr(user->GetPort()),listenports))
{
/* Hook the user with our module */
user->io = this;
@@ -625,7 +613,7 @@ class ModuleSSLGnuTLS : public Module
return;
// Bugfix, only send this numeric for *our* SSL users
- if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->GetPort(), listenports)))
+ if (dest->GetExt("ssl", dummy) || ((IS_LOCAL(dest) && (dest->io == this))))
{
ServerInstance->SendWhoisLine(source, dest, 320, "%s %s :is using a secure connection", source->nick, dest->nick);
}
diff --git a/src/socket.cpp b/src/socket.cpp
index 2089fffbd..16cdebae6 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -101,23 +101,42 @@ void ListenSocket::HandleEvent(EventType, int)
if ((incomingSockfd > -1) && (!ServerInstance->SE->GetSockName(this, sock_us, &uslen)))
{
char buf[MAXBUF];
+ char target[MAXBUF];
+
+ *target = *buf = '\0';
+
+ sockaddr* raddr = new sockaddr[2];
+
#ifdef IPV6
if (this->family == AF_INET6)
{
- inet_ntop(AF_INET6, &((const sockaddr_in6*)client)->sin6_addr, buf, sizeof(buf));
in_port = ntohs(((sockaddr_in6*)sock_us)->sin6_port);
+ inet_ntop(AF_INET6, &((const sockaddr_in6*)ip)->sin6_addr, buf, sizeof(buf));
+ socklen_t raddrsz = sizeof(sockaddr_in6);
+ if (getpeername(incomingSockfd, (sockaddr*) raddr, &raddrsz) == 0)
+ inet_ntop(AF_INET6, &((const sockaddr_in6*)raddr)->sin6_addr, target, sizeof(target));
+ else
+ ServerInstance->Logs->Log("SOCKET", DEBUG, "Can't get peername: %s", strerror(errno));
}
else
#endif
{
inet_ntop(AF_INET, &((const sockaddr_in*)client)->sin_addr, buf, sizeof(buf));
in_port = ntohs(((sockaddr_in*)sock_us)->sin_port);
+ socklen_t raddrsz = sizeof(sockaddr_in);
+ if (getpeername(incomingSockfd, (sockaddr*) raddr, &raddrsz) == 0)
+ inet_ntop(AF_INET, &((const sockaddr_in*)raddr)->sin_addr, target, sizeof(target));
+ else
+ ServerInstance->Logs->Log("SOCKET", DEBUG, "Can't get peername: %s", strerror(errno));
+
}
+ delete[] raddr;
+
ServerInstance->SE->NonBlocking(incomingSockfd);
ServerInstance->stats->statsAccept++;
- ServerInstance->Users->AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
+ ServerInstance->Users->AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client, target);
}
else
{
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index b518685fa..af76f5651 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -18,7 +18,7 @@
#include "bancache.h"
/* add a client connection to the sockets list */
-void UserManager::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, int socketfamily, sockaddr* ip)
+void UserManager::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, int socketfamily, sockaddr* ip, const std::string &targetip)
{
/* NOTE: Calling this one parameter constructor for User automatically
* allocates a new UUID and places it in the hash_map.
@@ -43,9 +43,11 @@ void UserManager::AddClient(InspIRCd* Instance, int socket, int port, bool iscac
#endif
inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr));
+ New->SetFd(socket);
+ New->SetSockAddr(socketfamily, ipaddr, port);
/* Give each of the modules an attempt to hook the user for I/O */
- FOREACH_MOD_I(Instance, I_OnHookUserIO, OnHookUserIO(New));
+ FOREACH_MOD_I(Instance, I_OnHookUserIO, OnHookUserIO(New, targetip));
if (New->io)
{
@@ -78,10 +80,6 @@ void UserManager::AddClient(InspIRCd* Instance, int socket, int port, bool iscac
New->signon = Instance->Time() + Instance->Config->dns_timeout;
New->lastping = 1;
- New->SetSockAddr(socketfamily, ipaddr, port);
-
- New->SetFd(socket);
-
/* Smarter than your average bear^H^H^H^Hset of strlcpys. */
for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
New->dhost[j] = New->host[j] = *temp;