summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp8
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp6
-rw-r--r--src/modules/extra/m_ziplink.cpp2
-rw-r--r--src/modules/m_cgiirc.cpp55
-rw-r--r--src/modules/m_cloaking.cpp27
-rw-r--r--src/modules/m_connectban.cpp2
-rw-r--r--src/modules/m_ident.cpp102
-rw-r--r--src/modules/m_spanningtree/uid.cpp2
-rw-r--r--src/modules/m_spanningtree/utils.cpp2
9 files changed, 54 insertions, 152 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 2fa060360..b2b59e612 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -81,7 +81,7 @@ class CommandStartTLS : public Command
{
user->WriteNumeric(670, "%s :STARTTLS successful, go ahead with TLS handshake", user->nick.c_str());
user->AddIOHook(Caller);
- Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), user->GetServerPort());
+ Caller->OnRawSocketAccept(user->GetFd(), NULL, NULL);
}
else
user->WriteNumeric(691, "%s :STARTTLS failure", user->nick.c_str());
@@ -347,9 +347,9 @@ class ModuleSSLGnuTLS : public Module
output.append(" STARTTLS");
}
- virtual void OnHookUserIO(User* user, const std::string &targetip)
+ virtual void OnHookUserIO(User* user)
{
- if (!user->GetIOHook() && isin(targetip,user->GetServerPort(),listenports))
+ if (!user->GetIOHook() && isin(user->GetServerIP(),user->GetServerPort(),listenports))
{
/* Hook the user with our module */
user->AddIOHook(this);
@@ -421,7 +421,7 @@ class ModuleSSLGnuTLS : public Module
}
- virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
+ virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
{
/* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1))
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index 0259c105a..447f35940 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -157,9 +157,9 @@ class ModuleSSLOpenSSL : public Module
ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
}
- virtual void OnHookUserIO(User* user, const std::string &targetip)
+ virtual void OnHookUserIO(User* user)
{
- if (!user->GetIOHook() && isin(targetip,user->GetServerPort(), listenports))
+ if (!user->GetIOHook() && isin(user->GetServerIP(),user->GetServerPort(), listenports))
{
/* Hook the user with our module */
user->AddIOHook(this);
@@ -424,7 +424,7 @@ class ModuleSSLOpenSSL : public Module
}
- virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
+ virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
{
/* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1))
diff --git a/src/modules/extra/m_ziplink.cpp b/src/modules/extra/m_ziplink.cpp
index b42d18f8c..efff13644 100644
--- a/src/modules/extra/m_ziplink.cpp
+++ b/src/modules/extra/m_ziplink.cpp
@@ -211,7 +211,7 @@ class ModuleZLib : public Module
session->status = IZIP_OPEN;
}
- virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
+ virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*)
{
/* Nothing special needs doing here compared to connect() */
OnRawSocketConnect(fd);
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index 85acae8ab..1467d0f68 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -117,7 +117,7 @@ class CGIResolver : public Resolver
them->host.assign(result,0, 64);
them->dhost.assign(result, 0, 64);
if (querytype)
- them->SetSockAddr(result.c_str(), them->GetServerPort());
+ them->SetClientIP(result.c_str());
them->ident.assign("~cgiirc", 0, 8);
them->InvalidateCache();
them->CheckLines(true);
@@ -318,7 +318,7 @@ public:
if(user->GetExt("cgiirc_webirc_ip", webirc_ip))
{
ServerInstance->Users->RemoveCloneCounts(user);
- user->SetSockAddr(webirc_ip->c_str(), user->GetServerPort());
+ user->SetClientIP(webirc_ip->c_str());
delete webirc_ip;
user->InvalidateCache();
user->Shrink("cgiirc_webirc_ip");
@@ -341,15 +341,7 @@ public:
bool valid = false;
ServerInstance->Users->RemoveCloneCounts(user);
-#ifdef IPV6
- if (user->ip.sa.sa_family == AF_INET6)
- valid = (inet_pton(AF_INET6, user->password.c_str(), &user->ip.in6.sin6_addr) > 0);
- else
- valid = (inet_aton(user->password.c_str(), &user->ip.in4.sin_addr));
-#else
- if (inet_aton(user->password.c_str(), &((sockaddr_in*)user->ip)->sin_addr))
- valid = true;
-#endif
+ valid = user->SetClientIP(user->password.c_str());
ServerInstance->Users->AddLocalClone(user);
ServerInstance->Users->AddGlobalClone(user);
user->CheckClass();
@@ -386,10 +378,9 @@ public:
bool CheckIdent(User* user)
{
- int ip[4];
const char* ident;
- char newip[16];
int len = user->ident.length();
+ in_addr newip;
if(len == 8)
ident = user->ident.c_str();
@@ -398,34 +389,32 @@ public:
else
return false;
- for(int i = 0; i < 4; i++)
- if(!HexToInt(ip[i], ident + i*2))
- return false;
-
- snprintf(newip, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+ errno = 0;
+ unsigned long ipaddr = strtoul(ident, NULL, 16);
+ if (errno)
+ return false;
+ newip.s_addr = htonl(ipaddr);
+ char* newipstr = inet_ntoa(newip);
user->Extend("cgiirc_realhost", new std::string(user->host));
user->Extend("cgiirc_realip", new std::string(user->GetIPString()));
ServerInstance->Users->RemoveCloneCounts(user);
- user->SetSockAddr(newip, user->GetServerPort());
+ user->SetClientIP(newipstr);
ServerInstance->Users->AddLocalClone(user);
ServerInstance->Users->AddGlobalClone(user);
user->CheckClass();
+ user->host = newipstr;
+ user->dhost = newipstr;
+ user->ident.assign("~cgiirc", 0, 8);
try
{
- user->host.assign(newip, 0, 16);
- user->dhost.assign(newip, 0, 16);
- user->ident.assign("~cgiirc", 0, 8);
bool cached;
- CGIResolver* r = new CGIResolver(this, ServerInstance, NotifyOpers, newip, false, user, user->GetFd(), "IDENT", cached);
+ CGIResolver* r = new CGIResolver(this, ServerInstance, NotifyOpers, newipstr, false, user, user->GetFd(), "IDENT", cached);
ServerInstance->AddResolver(r, cached);
}
catch (...)
{
- user->host.assign(newip, 0, 16);
- user->dhost.assign(newip, 0, 16);
- user->ident.assign("~cgiirc", 0, 8);
user->InvalidateCache();
if(NotifyOpers)
@@ -491,20 +480,6 @@ public:
return true;
}
- bool HexToInt(int &out, const char* in)
- {
- char ip[3];
- ip[0] = in[0];
- ip[1] = in[1];
- ip[2] = 0;
- out = strtol(ip, NULL, 16);
-
- if(out > 255 || out < 0)
- return false;
-
- return true;
- }
-
virtual ~ModuleCgiIRC()
{
}
diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp
index 29a5e1421..a17577702 100644
--- a/src/modules/m_cloaking.cpp
+++ b/src/modules/m_cloaking.cpp
@@ -410,35 +410,20 @@ class ModuleCloaking : public Module
* Their ISP shouldnt go to town on subdomains, or they shouldnt have a kiddie
* vhost.
*/
-#ifdef IPV6
in6_addr testaddr;
- in_addr testaddr2;
- if ((dest->ip.sa.sa_family == AF_INET6) && (inet_pton(AF_INET6,dest->host.c_str(),&testaddr) < 1) && (hostcloak.length() <= 64))
- /* Invalid ipv6 address, and ipv6 user (resolved host) */
- b = hostcloak;
- else if ((dest->ip.sa.sa_family == AF_INET) && (inet_aton(dest->host.c_str(),&testaddr2) < 1) && (hostcloak.length() <= 64))
- /* Invalid ipv4 address, and ipv4 user (resolved host) */
- b = hostcloak;
- else
- /* Valid ipv6 or ipv4 address (not resolved) ipv4 or ipv6 user */
- b = ((!strchr(dest->host.c_str(),':')) ? cu->Cloak4(dest->host.c_str()) : cu->Cloak6(dest->host.c_str()));
-#else
- in_addr testaddr;
- if ((inet_aton(dest->host.c_str(),&testaddr) < 1) && (hostcloak.length() <= 64))
- /* Invalid ipv4 address, and ipv4 user (resolved host) */
+ if (inet_pton(dest->client_sa.sa.sa_family, dest->host.c_str(), &testaddr) < 1 && (hostcloak.length() <= 64))
+ /* not a valid address, must have been a host, so cloak as a host */
b = hostcloak;
+ else if (dest->client_sa.sa.sa_family == AF_INET6)
+ b = cu->Cloak6(dest->GetIPString());
else
- /* Valid ipv4 address (not resolved) ipv4 user */
- b = cu->Cloak4(dest->host.c_str());
-#endif
+ b = cu->Cloak4(dest->GetIPString());
}
else
{
-#ifdef IPV6
- if (dest->ip.sa.sa_family == AF_INET6)
+ if (dest->client_sa.sa.sa_family == AF_INET6)
b = cu->Cloak6(dest->GetIPString());
else
-#endif
b = cu->Cloak4(dest->GetIPString());
}
diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp
index a00fc6733..ae464a16c 100644
--- a/src/modules/m_connectban.cpp
+++ b/src/modules/m_connectban.cpp
@@ -72,7 +72,7 @@ class ModuleConnectBan : public Module
int range = 32;
clonemap::iterator i;
- switch (u->ip.sa.sa_family)
+ switch (u->client_sa.sa.sa_family)
{
case AF_INET6:
range = ipv6_cidr;
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index d5ca20836..80f2c0b99 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -80,60 +80,36 @@ class IdentRequestSocket : public EventHandler
std::string result; /* Holds the ident string if done */
public:
- IdentRequestSocket(InspIRCd *Server, User* u, const std::string &bindip) : user(u), ServerInstance(Server), result(u->ident)
+ IdentRequestSocket(InspIRCd *Server, User* u) : user(u), ServerInstance(Server), result(u->ident)
{
socklen_t size = 0;
-#ifdef IPV6
- /* Does this look like a v6 ip address? */
- bool v6 = false;
- if ((bindip.empty()) || bindip.find(':') != std::string::npos)
- v6 = true;
-
- if (v6)
- SetFd(socket(AF_INET6, SOCK_STREAM, 0));
- else
-#endif
- SetFd(socket(AF_INET, SOCK_STREAM, 0));
+
+ SetFd(socket(user->server_sa.sa.sa_family, SOCK_STREAM, 0));
if (GetFd() == -1)
throw ModuleException("Could not create socket");
done = false;
- /* We allocate two of these because sizeof(sockaddr_in6) > sizeof(sockaddr_in) */
- irc::sockets::sockaddrs s;
- irc::sockets::sockaddrs addr;
+ irc::sockets::sockaddrs bindaddr;
+ irc::sockets::sockaddrs connaddr;
+
+ memcpy(&bindaddr, &user->server_sa, sizeof(bindaddr));
+ memcpy(&connaddr, &user->client_sa, sizeof(connaddr));
-#ifdef IPV6
- /* Horrid icky nasty ugly berkely socket crap. */
- if (v6)
+ if (connaddr.sa.sa_family == AF_INET6)
{
- if (inet_pton(AF_INET6, user->GetIPString(), &addr.in6.sin6_addr) > 0)
- {
- addr.in6.sin6_family = AF_INET6;
- addr.in6.sin6_port = htons(113);
- size = sizeof(sockaddr_in6);
- inet_pton(AF_INET6, bindip.c_str(), &s.in6.sin6_addr);
- s.in6.sin6_family = AF_INET6;
- s.in6.sin6_port = 0;
- }
+ bindaddr.in6.sin6_port = 0;
+ connaddr.in6.sin6_port = htons(113);
}
else
-#endif
{
- if (inet_aton(user->GetIPString(), &addr.in4.sin_addr) > 0)
- {
- addr.in4.sin_family = AF_INET;
- addr.in4.sin_port = htons(113);
- size = sizeof(sockaddr_in);
- inet_aton(bindip.c_str(), &s.in4.sin_addr);
- s.in4.sin_family = AF_INET;
- s.in4.sin_port = 0;
- }
+ bindaddr.in4.sin_port = 0;
+ connaddr.in4.sin_port = htons(113);
}
/* Attempt to bind (ident requests must come from the ip the query is referring to */
- if (ServerInstance->SE->Bind(GetFd(), &s.sa, size) < 0)
+ if (ServerInstance->SE->Bind(GetFd(), &bindaddr.sa, size) < 0)
{
this->Close();
throw ModuleException("failed to bind()");
@@ -142,7 +118,7 @@ class IdentRequestSocket : public EventHandler
ServerInstance->SE->NonBlocking(GetFd());
/* Attempt connection (nonblocking) */
- if (ServerInstance->SE->Connect(this, &addr.sa, size) == -1 && errno != EINPROGRESS)
+ if (ServerInstance->SE->Connect(this, &connaddr.sa, size) == -1 && errno != EINPROGRESS)
{
this->Close();
throw ModuleException("connect() failed");
@@ -165,30 +141,16 @@ class IdentRequestSocket : public EventHandler
{
ServerInstance->Logs->Log("m_ident",DEBUG,"OnConnected()");
- /* Both sockaddr_in and sockaddr_in6 can be safely casted to sockaddr, especially since the
- * only members we use are in a part of the struct that should always be identical (at the
- * byte level). */
- irc::sockets::sockaddrs laddr, raddr;
-
- socklen_t laddrsz = sizeof(laddr);
- socklen_t raddrsz = sizeof(raddr);
-
- if ((getsockname(user->GetFd(), &laddr.sa, &laddrsz) != 0) || (getpeername(user->GetFd(), &raddr.sa, &raddrsz) != 0))
- {
- done = true;
- return;
- }
-
char req[32];
/* Build request in the form 'localport,remoteport\r\n' */
int req_size;
-#ifdef IPV6
- if (raddr.sa.sa_family == AF_INET6)
- req_size = snprintf(req, sizeof(req), "%d,%d\r\n", ntohs(raddr.in6.sin6_port), ntohs(laddr.in6.sin6_port));
+ if (user->client_sa.sa.sa_family == AF_INET6)
+ req_size = snprintf(req, sizeof(req), "%d,%d\r\n",
+ ntohs(user->client_sa.in6.sin6_port), ntohs(user->server_sa.in6.sin6_port));
else
-#endif
- req_size = snprintf(req, sizeof(req), "%d,%d\r\n", ntohs(raddr.in4.sin_port), ntohs(laddr.in4.sin_port));
+ req_size = snprintf(req, sizeof(req), "%d,%d\r\n",
+ ntohs(user->client_sa.in4.sin_port), ntohs(user->server_sa.in4.sin_port));
/* Send failed if we didnt write the whole ident request --
* might as well give up if this happens!
@@ -371,36 +333,16 @@ class ModuleIdent : public Module
user->WriteServ("NOTICE Auth :*** Looking up your ident...");
- // Get the IP that the user is connected to, and bind to that for the outgoing connection
- irc::sockets::sockaddrs laddr;
- socklen_t laddrsz = sizeof(laddr);
-
- if (getsockname(user->GetFd(), &laddr.sa, &laddrsz) != 0)
- {
- user->WriteServ("NOTICE Auth :*** Could not find your ident, using %s instead.", user->ident.c_str());
- return 0;
- }
-
- char ip[INET6_ADDRSTRLEN + 1];
-#ifdef IPV6
- if (laddr.sa.sa_family == AF_INET6)
- inet_ntop(laddr.in6.sin6_family, &laddr.in6.sin6_addr, ip, INET6_ADDRSTRLEN);
- else
-#endif
- inet_ntop(laddr.in4.sin_family, &laddr.in4.sin_addr, ip, INET6_ADDRSTRLEN);
-
- IdentRequestSocket *isock = NULL;
try
{
- isock = new IdentRequestSocket(ServerInstance, user, ip);
+ IdentRequestSocket *isock = new IdentRequestSocket(ServerInstance, user);
+ user->Extend("ident_socket", isock);
}
catch (ModuleException &e)
{
ServerInstance->Logs->Log("m_ident",DEBUG,"Ident exception: %s", e.GetReason());
- return 0;
}
- user->Extend("ident_socket", isock);
return 0;
}
diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp
index 5b155e188..7565be337 100644
--- a/src/modules/m_spanningtree/uid.cpp
+++ b/src/modules/m_spanningtree/uid.cpp
@@ -157,7 +157,7 @@ bool TreeSocket::ParseUID(const std::string &source, std::deque<std::string> &pa
if (params[8][0] != '+')
params[8] = "+" + params[8];
- _new->SetSockAddr(params[6].c_str(), 0);
+ _new->SetClientIP(params[6].c_str());
ServerInstance->Users->AddGlobalClone(_new);
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index 116ac741f..8a17baf84 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -56,7 +56,7 @@ void ServerSocketListener::OnAcceptReady(const std::string &ipconnectedto, int n
if (this->GetIOHook())
{
- this->GetIOHook()->OnRawSocketAccept(newsock, incomingip.c_str(), this->bind_port);
+ this->GetIOHook()->OnRawSocketAccept(newsock, &client, &server);
}
/* we don't need a pointer to this, creating it stores it in the necessary places */