summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp1
-rw-r--r--src/inspsocket.cpp38
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp5
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp8
-rw-r--r--src/modules/m_spanningtree.cpp33
5 files changed, 65 insertions, 20 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 7729cee69..b0106eb5e 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -81,6 +81,7 @@ bool ServerConfig::AddIOHook(Module* iomod, InspSocket* is)
{
if (!GetIOHook(is))
{
+ ServerInstance->Log(DEBUG,"Hooked inspsocket %08x", is);
SocketIOHookModule[is] = iomod;
is->IsIOHooked = true;
return true;
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index 23d89a71f..1096162db 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -259,7 +259,7 @@ void InspSocket::Close()
{
if (this->fd > -1)
{
- if (this->IsIOHooked)
+ if (this->IsIOHooked && Instance->Config->GetIOHook(this))
{
try
{
@@ -367,7 +367,30 @@ bool InspSocket::FlushWriteBuffer()
{
try
{
- Instance->Config->GetIOHook(this)->OnRawSocketWrite(this->fd, outbuffer[0].c_str(), outbuffer[0].length());
+ Instance->Log(DEBUG,"To write: %s", outbuffer[0].c_str());
+ int result = Instance->Config->GetIOHook(this)->OnRawSocketWrite(this->fd, outbuffer[0].c_str(), outbuffer[0].length());
+ if (result > 0)
+ {
+ if ((unsigned int)result == outbuffer[0].length())
+ {
+ outbuffer.pop_front();
+ }
+ else
+ {
+ std::string temp = outbuffer[0].substr(result);
+ outbuffer[0] = temp;
+ errno = EAGAIN;
+ }
+ }
+ else if ((result == -1) && (errno != EAGAIN))
+ {
+ this->Instance->Log(DEBUG,"Write error on socket: %s",strerror(errno));
+ this->OnError(I_ERR_WRITE);
+ this->state = I_ERROR;
+ this->Instance->SE->DelFd(this);
+ this->Close();
+ return true;
+ }
}
catch (ModuleException& modexcept)
{
@@ -500,6 +523,12 @@ bool InspSocket::Poll()
length = sizeof (client);
incoming = accept (this->fd, (sockaddr*)&client,&length);
+#ifdef IPV6
+ this->OnIncomingConnection(incoming, (char*)insp_ntoa(client.sin6_addr));
+#else
+ this->OnIncomingConnection(incoming, (char*)insp_ntoa(client.sin_addr));
+#endif
+
if (this->IsIOHooked)
{
try
@@ -517,11 +546,6 @@ bool InspSocket::Poll()
}
this->SetQueues(incoming);
-#ifdef IPV6
- this->OnIncomingConnection(incoming, (char*)insp_ntoa(client.sin6_addr));
-#else
- this->OnIncomingConnection(incoming, (char*)insp_ntoa(client.sin_addr));
-#endif
return true;
break;
case I_CONNECTED:
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 4f22a5e70..0006c9de9 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -445,7 +445,10 @@ class ModuleSSLGnuTLS : public Module
}
virtual int OnRawSocketWrite(int fd, const char* buffer, int count)
- {
+ {
+ if (!count)
+ return 0;
+
issl_session* session = &sessions[fd];
const char* sendbuffer = buffer;
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index 0da67d677..06708ff54 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -296,16 +296,19 @@ class ModuleSSLOpenSSL : public Module
virtual char* OnRequest(Request* request)
{
ISHRequest* ISR = (ISHRequest*)request;
+ ServerInstance->Log(DEBUG, "hook OnRequest");
if (strcmp("IS_NAME", request->GetId()) == 0)
{
return "openssl";
}
else if (strcmp("IS_HOOK", request->GetId()) == 0)
{
+ ServerInstance->Log(DEBUG, "Hooking socket %08x", ISR->Sock);
return ServerInstance->Config->AddIOHook((Module*)this, (InspSocket*)ISR->Sock) ? (char*)"OK" : NULL;
}
else if (strcmp("IS_UNHOOK", request->GetId()) == 0)
{
+ ServerInstance->Log(DEBUG, "Unhooking socket %08x", ISR->Sock);
return ServerInstance->Config->DelIOHook((InspSocket*)ISR->Sock) ? (char*)"OK" : NULL;
}
return NULL;
@@ -314,6 +317,7 @@ class ModuleSSLOpenSSL : public Module
virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
{
+ ServerInstance->Log(DEBUG, "Hook accept %d", fd);
issl_session* session = &sessions[fd];
session->fd = fd;
@@ -515,6 +519,10 @@ class ModuleSSLOpenSSL : public Module
int DoWrite(issl_session* session)
{
+ if (!session->outbuf.size())
+ return -1;
+
+ ServerInstance->Log(DEBUG, "m_ssl_openssl.so: To write: %d", session->outbuf.size());
int ret = SSL_write(session->sess, session->outbuf.data(), session->outbuf.size());
if (ret == 0)
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index a0563c255..e96656910 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -680,8 +680,10 @@ class TreeSocket : public InspSocket
this->ctx_in = NULL;
this->ctx_out = NULL;
- if (Hook)
- InspSocketHookRequest(this, Hook, (Module*)Utils->Creator).Send();
+ Instance->Log(DEBUG, "HOOK = %08x", Hook);
+
+ if (listening && Hook)
+ InspSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
}
TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string host, int port, bool listening, unsigned long maxtime, std::string ServerName, Module* HookMod = NULL)
@@ -691,9 +693,6 @@ class TreeSocket : public InspSocket
this->LinkState = CONNECTING;
this->ctx_in = NULL;
this->ctx_out = NULL;
-
- if (Hook)
- InspSocketHookRequest(this, Hook, (Module*)Utils->Creator).Send();
}
/** When a listening socket gives us a new file descriptor,
@@ -701,16 +700,18 @@ class TreeSocket : public InspSocket
* connection. This constructor is used for this purpose.
*/
TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, int newfd, char* ip, Module* HookMod = NULL)
- : InspSocket(SI, newfd, ip), Utils(Util)
+ : InspSocket(SI, newfd, ip), Utils(Util), Hook(HookMod)
{
this->LinkState = WAIT_AUTH_1;
this->ctx_in = NULL;
this->ctx_out = NULL;
+ Instance->Log(DEBUG, "HOOK = %08x", Hook);
+
if (Hook)
- InspSocketHookRequest(this, Hook, (Module*)Utils->Creator).Send();
+ InspSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
- this->SendCapabilities();
+ //this->SendCapabilities();
}
~TreeSocket()
@@ -721,7 +722,7 @@ class TreeSocket : public InspSocket
DELETE(ctx_out);
if (Hook)
- InspSocketUnhookRequest(this, Hook, (Module*)Utils->Creator).Send();
+ InspSocketUnhookRequest(this, (Module*)Utils->Creator, Hook).Send();
}
void InitAES(std::string key,std::string SName)
@@ -768,7 +769,11 @@ class TreeSocket : public InspSocket
if (x->Name == this->myhost)
{
this->Instance->SNO->WriteToSnoMask('l',"Connection to \2"+myhost+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] started.");
- this->SendCapabilities();
+
+ if (Hook)
+ InspSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
+
+ //this->SendCapabilities();
if (x->EncryptionKey != "")
{
if (!(x->EncryptionKey.length() == 16 || x->EncryptionKey.length() == 24 || x->EncryptionKey.length() == 32))
@@ -4100,8 +4105,12 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
if (IP == "*")
IP = "";
- if ((!transport.empty()) && (hooks.find(transport.c_str()) == hooks.end()))
- return;
+ if ((!transport.empty()) && (hooks.find(transport.c_str()) == hooks.end()))
+ {
+ ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' - maybe you forgot to load it BEFORE m_spanningtree in your config file?",
+ transport.c_str());
+ continue;
+ }
TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
if (listener->GetState() == I_LISTENING)