diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-09 18:49:36 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-09 18:49:36 +0000 |
commit | 768171fef96d3e0b74b5c750e7887fc20b48331c (patch) | |
tree | 449ee5c880d1261fbba98893c7860910249a8adb | |
parent | dfa831752c950f16872f3c485f94d408866a2e15 (diff) |
Add OnRawSocketConnect, we've not had it till now because we've not needed it :)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5887 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/modules.h | 4 | ||||
-rw-r--r-- | src/cmd_modules.cpp | 2 | ||||
-rw-r--r-- | src/inspsocket.cpp | 11 | ||||
-rw-r--r-- | src/modules.cpp | 1 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 21 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_openssl.cpp | 27 |
6 files changed, 62 insertions, 4 deletions
diff --git a/include/modules.h b/include/modules.h index 670d32844..9ace806b7 100644 --- a/include/modules.h +++ b/include/modules.h @@ -371,7 +371,7 @@ enum Implementation { I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUse I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnOperCompre, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan, I_OnDelBan, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList, - I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList }; + I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect }; /** Base class for all InspIRCd modules * This class is the base class for InspIRCd modules. All modules must inherit from this class, @@ -1270,6 +1270,8 @@ class Module : public Extensible */ virtual void OnRawSocketClose(int fd); + virtual void OnRawSocketConnect(int fd); + /** Called immediately before any read() operation on a client socket in the core. * This occurs AFTER the select() or poll() so there is always data waiting to be read * when this event occurs. diff --git a/src/cmd_modules.cpp b/src/cmd_modules.cpp index 56df9cc60..bd5848d92 100644 --- a/src/cmd_modules.cpp +++ b/src/cmd_modules.cpp @@ -34,7 +34,7 @@ char* itab[] = { "OnPostLocalTopicChange", "OnEvent", "OnRequest", "OnOperCompre", "OnGlobalOper", "OnPostConnect", "OnAddBan", "OnDelBan", "OnRawSocketAccept", "OnRawSocketClose", "OnRawSocketWrite", "OnRawSocketRead", "OnChangeLocalUserGECOS", "OnUserRegister", "OnOperCompare", "OnChannelDelete", "OnPostOper", "OnSyncOtherMetaData", "OnSetAway", "OnCancelAway", "OnNamesList", - "OnPostCommand", "OnPostJoin", "OnWhoisLine", "OnBuildExemptList", NULL + "OnPostCommand", "OnPostJoin", "OnWhoisLine", "OnBuildExemptList", "OnRawSocketConnect", NULL }; extern "C" command_t* init_command(InspIRCd* Instance) diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 9d2745a2d..23d89a71f 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -483,6 +483,17 @@ bool InspSocket::Poll() if (!this->Instance->SE->AddFd(this)) return false; } + if (this->IsIOHooked) + { + try + { + Instance->Config->GetIOHook(this)->OnRawSocketConnect(this->fd); + } + catch (ModuleException& modexcept) + { + Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); + } + } return this->OnConnected(); break; case I_LISTENING: diff --git a/src/modules.cpp b/src/modules.cpp index 786570a40..4ae033c8b 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -156,6 +156,7 @@ int Module::OnDelBan(userrec* source, chanrec* channel,const std::string &banma void Module::OnRawSocketAccept(int fd, const std::string &ip, int localport) { }; int Module::OnRawSocketWrite(int fd, const char* buffer, int count) { return 0; }; void Module::OnRawSocketClose(int fd) { }; +void Module::OnRawSocketConnect(int fd) { }; int Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; }; void Module::OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { }; void Module::OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { }; diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index dfa22f2f2..d0e2e7df2 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -252,7 +252,7 @@ class ModuleSSLGnuTLS : public Module void Implements(char* List) { - List[I_OnRawSocketAccept] = List[I_OnRawSocketClose] = List[I_OnRawSocketRead] = List[I_OnRawSocketWrite] = List[I_OnCleanup] = 1; + List[I_OnRawSocketConnect] = List[I_OnRawSocketAccept] = List[I_OnRawSocketClose] = List[I_OnRawSocketRead] = List[I_OnRawSocketWrite] = List[I_OnCleanup] = 1; List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnUnloadModule] = List[I_OnRehash] = List[I_OnWhois] = List[I_OnPostConnect] = 1; } @@ -284,6 +284,25 @@ class ModuleSSLGnuTLS : public Module Handshake(session); } + virtual void OnRawSocketConnect(int fd) + { + issl_session* session = &sessions[fd]; + + session->fd = fd; + session->inbuf = new char[inbufsize]; + session->inbufoffset = 0; + + gnutls_init(&session->sess, GNUTLS_SERVER); + + gnutls_set_default_priority(session->sess); // Avoid calling all the priority functions, defaults are adequate. + gnutls_credentials_set(session->sess, GNUTLS_CRD_CERTIFICATE, x509_cred); + gnutls_dh_set_prime_bits(session->sess, dh_bits); + + gnutls_transport_set_ptr(session->sess, (gnutls_transport_ptr_t) fd); // Give gnutls the fd for the socket. + + Handshake(session); + } + virtual void OnRawSocketClose(int fd) { ServerInstance->Log(DEBUG, "OnRawSocketClose: %d", fd); diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index 760b4c35a..bd0763f4c 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -287,7 +287,7 @@ class ModuleSSLOpenSSL : public Module void Implements(char* List) { - List[I_OnRawSocketAccept] = List[I_OnRawSocketClose] = List[I_OnRawSocketRead] = List[I_OnRawSocketWrite] = List[I_OnCleanup] = 1; + List[I_OnRawSocketConnect] = List[I_OnRawSocketAccept] = List[I_OnRawSocketClose] = List[I_OnRawSocketRead] = List[I_OnRawSocketWrite] = List[I_OnCleanup] = 1; List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnUnloadModule] = List[I_OnRehash] = List[I_OnWhois] = List[I_OnPostConnect] = 1; } @@ -316,6 +316,31 @@ class ModuleSSLOpenSSL : public Module Handshake(session); } + virtual void OnRawSocketConnect(int fd) + { + issl_session* session = &sessions[fd]; + + session->fd = fd; + session->inbuf = new char[inbufsize]; + session->inbufoffset = 0; + session->sess = SSL_new(ctx); + session->status = ISSL_NONE; + + if (session->sess == NULL) + { + ServerInstance->Log(DEBUG, "m_ssl.so: Couldn't create SSL object: %s", get_error()); + return; + } + + if (SSL_set_fd(session->sess, fd) == 0) + { + ServerInstance->Log(DEBUG, "m_ssl.so: Couldn't set fd for SSL object: %s", get_error()); + return; + } + + Handshake(session); + } + virtual void OnRawSocketClose(int fd) { ServerInstance->Log(DEBUG, "m_ssl_openssl.so: OnRawSocketClose: %d", fd); |