mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 02:59:01 -04:00
Add server ports to ServerInstance->ports, enable SSL on them using OnHookIO
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11810 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
c4d6ce8c5e
commit
b6a5e2bd14
@ -124,8 +124,6 @@ namespace irc
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** This class handles incoming connections on client ports.
|
||||
* It will create a new User for every valid connection
|
||||
* and assign it a file descriptor.
|
||||
@ -133,13 +131,8 @@ namespace irc
|
||||
class CoreExport ListenSocketBase : public EventHandler
|
||||
{
|
||||
protected:
|
||||
/** Socket description (shown in stats p) */
|
||||
std::string desc;
|
||||
|
||||
/** Raw address socket is bound to */
|
||||
std::string bind_addr;
|
||||
/** Port socket is bound to */
|
||||
int bind_port;
|
||||
/** Human-readable address/port socket is bound to */
|
||||
std::string bind_desc;
|
||||
|
||||
@ -155,27 +148,21 @@ class CoreExport ListenSocketBase : public EventHandler
|
||||
static irc::sockets::sockaddrs server;
|
||||
|
||||
public:
|
||||
/** Socket type (client/server) */
|
||||
const std::string type;
|
||||
/** Socket hook (plain/gnutls/openssl/zip) */
|
||||
const std::string hook;
|
||||
/** Port socket is bound to */
|
||||
const int bind_port;
|
||||
/** Create a new listening socket
|
||||
*/
|
||||
ListenSocketBase(int port, const std::string &addr);
|
||||
ListenSocketBase(int port, const std::string &addr, const std::string &type, const std::string &hook);
|
||||
/** Handle an I/O event
|
||||
*/
|
||||
void HandleEvent(EventType et, int errornum = 0);
|
||||
/** Close the socket
|
||||
*/
|
||||
~ListenSocketBase();
|
||||
/** Set descriptive text
|
||||
*/
|
||||
void SetDescription(const std::string &description)
|
||||
{
|
||||
desc = description;
|
||||
}
|
||||
/** Get description for socket
|
||||
*/
|
||||
const std::string& GetDescription() { return desc; }
|
||||
/** Get port number for socket
|
||||
*/
|
||||
int GetPort() const { return bind_port; }
|
||||
|
||||
/** Get IP address socket is bound to
|
||||
*/
|
||||
@ -197,7 +184,8 @@ class CoreExport ClientListenSocket : public ListenSocketBase
|
||||
{
|
||||
virtual void OnAcceptReady(int fd);
|
||||
public:
|
||||
ClientListenSocket(int port, const std::string &addr) : ListenSocketBase(port, addr) { }
|
||||
ClientListenSocket(int port, const std::string &addr, const std::string &Type, const std::string &Hook)
|
||||
: ListenSocketBase(port, addr, Type, Hook) { }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -21,7 +21,8 @@
|
||||
irc::sockets::sockaddrs ListenSocketBase::client;
|
||||
irc::sockets::sockaddrs ListenSocketBase::server;
|
||||
|
||||
ListenSocketBase::ListenSocketBase(int port, const std::string &addr) : desc("plaintext")
|
||||
ListenSocketBase::ListenSocketBase(int port, const std::string &addr, const std::string &Type, const std::string &Hook)
|
||||
: type(Type), hook(Hook), bind_port(port)
|
||||
{
|
||||
irc::sockets::sockaddrs bind_to;
|
||||
|
||||
@ -30,13 +31,12 @@ ListenSocketBase::ListenSocketBase(int port, const std::string &addr) : desc("pl
|
||||
{
|
||||
// malformed address
|
||||
bind_addr = addr;
|
||||
bind_port = port;
|
||||
bind_desc = addr + ":" + ConvToStr(port);
|
||||
this->fd = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
irc::sockets::satoap(&bind_to, bind_addr, bind_port);
|
||||
irc::sockets::satoap(&bind_to, bind_addr, port);
|
||||
bind_desc = irc::sockets::satouser(&bind_to);
|
||||
|
||||
this->fd = irc::sockets::OpenTCPSocket(bind_addr);
|
||||
|
@ -74,7 +74,7 @@ class SQLiteListener : public ListenSocketBase
|
||||
FileReader* index;
|
||||
|
||||
public:
|
||||
SQLiteListener(ModuleSQLite3* P, int port, const std::string &addr) : ListenSocketBase(port, addr), Parent(P)
|
||||
SQLiteListener(ModuleSQLite3* P, int port, const std::string &addr) : ListenSocketBase(port, addr, "ITC", "none"), Parent(P)
|
||||
{
|
||||
uslen = sizeof(sock_us);
|
||||
if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
|
||||
|
@ -122,8 +122,6 @@ class CommandStartTLS : public Command
|
||||
|
||||
class ModuleSSLGnuTLS : public Module
|
||||
{
|
||||
std::set<ListenSocketBase*> listenports;
|
||||
|
||||
issl_session* sessions;
|
||||
|
||||
gnutls_certificate_credentials x509_cred;
|
||||
@ -171,21 +169,18 @@ class ModuleSSLGnuTLS : public Module
|
||||
{
|
||||
ConfigReader Conf;
|
||||
|
||||
listenports.clear();
|
||||
sslports.clear();
|
||||
|
||||
for (size_t i = 0; i < ServerInstance->ports.size(); i++)
|
||||
{
|
||||
ListenSocketBase* port = ServerInstance->ports[i];
|
||||
std::string desc = port->GetDescription();
|
||||
if (desc != "gnutls")
|
||||
if (port->hook != "gnutls")
|
||||
continue;
|
||||
|
||||
listenports.insert(port);
|
||||
std::string portid = port->GetBindDesc();
|
||||
|
||||
const std::string& portid = port->GetBindDesc();
|
||||
ServerInstance->Logs->Log("m_ssl_gnutls", DEFAULT, "m_ssl_gnutls.so: Enabling SSL for port %s", portid.c_str());
|
||||
if (port->GetIP() != "127.0.0.1")
|
||||
|
||||
if (port->type == "clients" && port->GetIP() != "127.0.0.1")
|
||||
sslports.append(portid).append(";");
|
||||
}
|
||||
|
||||
@ -345,7 +340,7 @@ class ModuleSSLGnuTLS : public Module
|
||||
|
||||
void OnHookIO(StreamSocket* user, ListenSocketBase* lsb)
|
||||
{
|
||||
if (!user->GetIOHook() && listenports.find(lsb) != listenports.end())
|
||||
if (!user->GetIOHook() && lsb->hook == "gnutls")
|
||||
{
|
||||
/* Hook the user with our module */
|
||||
user->AddIOHook(this);
|
||||
|
@ -81,8 +81,6 @@ static int OnVerify(int preverify_ok, X509_STORE_CTX *ctx)
|
||||
|
||||
class ModuleSSLOpenSSL : public Module
|
||||
{
|
||||
std::set<ListenSocketBase*> listenports;
|
||||
|
||||
int inbufsize;
|
||||
issl_session* sessions;
|
||||
|
||||
@ -135,7 +133,7 @@ class ModuleSSLOpenSSL : public Module
|
||||
|
||||
void OnHookIO(StreamSocket* user, ListenSocketBase* lsb)
|
||||
{
|
||||
if (!user->GetIOHook() && listenports.find(lsb) != listenports.end())
|
||||
if (!user->GetIOHook() && lsb->hook == "openssl")
|
||||
{
|
||||
/* Hook the user with our module */
|
||||
user->AddIOHook(this);
|
||||
@ -146,21 +144,17 @@ class ModuleSSLOpenSSL : public Module
|
||||
{
|
||||
ConfigReader Conf;
|
||||
|
||||
listenports.clear();
|
||||
sslports.clear();
|
||||
|
||||
for (size_t i = 0; i < ServerInstance->ports.size(); i++)
|
||||
{
|
||||
ListenSocketBase* port = ServerInstance->ports[i];
|
||||
std::string desc = port->GetDescription();
|
||||
if (desc != "openssl")
|
||||
if (port->hook != "openssl")
|
||||
continue;
|
||||
|
||||
listenports.insert(port);
|
||||
std::string portid = port->GetBindDesc();
|
||||
|
||||
ServerInstance->Logs->Log("m_ssl_openssl", DEFAULT, "m_ssl_openssl.so: Enabling SSL for port %s", portid.c_str());
|
||||
if (port->GetIP() != "127.0.0.1")
|
||||
if (port->type == "clients" && port->GetIP() != "127.0.0.1")
|
||||
sslports.append(portid).append(";");
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,8 @@ class HttpListener : public ListenSocketBase
|
||||
FileReader* index;
|
||||
|
||||
public:
|
||||
HttpListener(FileReader *idx, int port, const std::string &addr) : ListenSocketBase(port, addr)
|
||||
HttpListener(FileReader *idx, int port, const std::string &addr)
|
||||
: ListenSocketBase(port, addr, "httpd", "plaintext")
|
||||
{
|
||||
this->index = idx;
|
||||
}
|
||||
|
@ -65,23 +65,6 @@ ModResult ModuleSpanningTree::OnStats(char statschar, User* user, string_list &r
|
||||
}
|
||||
return MOD_RES_DENY;
|
||||
}
|
||||
|
||||
if (statschar == 'p')
|
||||
{
|
||||
/* show all server ports, after showing client ports. -- w00t */
|
||||
|
||||
for (unsigned int i = 0; i < Utils->Bindings.size(); i++)
|
||||
{
|
||||
std::string ip = Utils->Bindings[i]->GetIP();
|
||||
if (ip.empty())
|
||||
ip = "*";
|
||||
|
||||
std::string transport(Utils->Bindings[i]->Hook);
|
||||
|
||||
results.push_back(ServerInstance->Config->ServerName + " 249 "+user->nick+" :" + ip + ":" + ConvToStr(Utils->Bindings[i]->GetPort())+
|
||||
" (server, " + transport + ")");
|
||||
}
|
||||
}
|
||||
return MOD_RES_PASSTHRU;
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,30 @@ TreeSocket::TreeSocket(SpanningTreeUtilities* Util, const std::string& shost, in
|
||||
capab_phase = 0;
|
||||
proto_version = 0;
|
||||
LinkState = CONNECTING;
|
||||
if (!hook.empty())
|
||||
{
|
||||
modulelist* ml = ServerInstance->Modules->FindInterface("BufferedSocketHook");
|
||||
if (ml)
|
||||
{
|
||||
for(modulelist::iterator i = ml->begin(); i != ml->end(); ++i)
|
||||
{
|
||||
std::string name = (**i).ModuleSourceFile;
|
||||
int a = name.rfind('_');
|
||||
int b = name.rfind('.');
|
||||
name = name.substr(a, b-a-1);
|
||||
if (name == hook)
|
||||
{
|
||||
AddIOHook(*i);
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
}
|
||||
SetError("Could not find hook '" + hook + "' for connection to " + ServerName);
|
||||
return;
|
||||
}
|
||||
found:
|
||||
DoConnect(shost, iport, maxtime, bindto);
|
||||
Utils->timeoutlist[this] = std::pair<std::string, int>(ServerName, maxtime);
|
||||
// TODO AddIOHook using the given hook
|
||||
SendCapabilities(1);
|
||||
}
|
||||
|
||||
|
@ -153,9 +153,10 @@ SpanningTreeUtilities::SpanningTreeUtilities(ModuleSpanningTree* C) : Creator(C)
|
||||
|
||||
bool SpanningTreeUtilities::cull()
|
||||
{
|
||||
for (unsigned int i = 0; i < Bindings.size(); i++)
|
||||
for (unsigned int i = 0; i < ServerInstance->ports.size(); i++)
|
||||
{
|
||||
Bindings[i]->cull();
|
||||
if (ServerInstance->ports[i]->type == "servers")
|
||||
ServerInstance->ports[i]->cull();
|
||||
}
|
||||
|
||||
while (TreeRoot->ChildCount())
|
||||
@ -177,9 +178,10 @@ bool SpanningTreeUtilities::cull()
|
||||
|
||||
SpanningTreeUtilities::~SpanningTreeUtilities()
|
||||
{
|
||||
for (unsigned int i = 0; i < Bindings.size(); i++)
|
||||
for (unsigned int i = 0; i < ServerInstance->ports.size(); i++)
|
||||
{
|
||||
delete Bindings[i];
|
||||
if (ServerInstance->ports[i]->type == "servers")
|
||||
delete ServerInstance->ports[i];
|
||||
}
|
||||
|
||||
delete TreeRoot;
|
||||
@ -383,12 +385,6 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
|
||||
|
||||
if (rebind)
|
||||
{
|
||||
for (unsigned int i = 0; i < Bindings.size(); i++)
|
||||
{
|
||||
delete Bindings[i];
|
||||
}
|
||||
Bindings.clear();
|
||||
|
||||
for (int j = 0; j < Conf->Enumerate("bind"); j++)
|
||||
{
|
||||
std::string Type = Conf->ReadValue("bind","type",j);
|
||||
@ -412,7 +408,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
|
||||
continue;
|
||||
}
|
||||
|
||||
Bindings.push_back(listener);
|
||||
ServerInstance->ports.push_back(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -448,7 +444,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
|
||||
L->Fingerprint = Conf->ReadValue("link", "fingerprint", j);
|
||||
L->HiddenFromStats = Conf->ReadFlag("link", "statshidden", j);
|
||||
L->Timeout = Conf->ReadInteger("link", "timeout", j, true);
|
||||
L->Hook = Conf->ReadValue("link", "transport", j);
|
||||
L->Hook = Conf->ReadValue("link", "ssl", j);
|
||||
L->Bind = Conf->ReadValue("link", "bind", j);
|
||||
L->Hidden = Conf->ReadFlag("link", "hidden", j);
|
||||
|
||||
|
@ -45,13 +45,11 @@ class ServerSocketListener : public ListenSocketBase
|
||||
SpanningTreeUtilities *Utils;
|
||||
|
||||
public:
|
||||
ServerSocketListener(SpanningTreeUtilities *u, int port, const std::string& addr, const std::string& hook)
|
||||
: ListenSocketBase(port, addr), Utils(u), Hook(hook)
|
||||
ServerSocketListener(SpanningTreeUtilities *u, int port, const std::string& addr, const std::string& Hook)
|
||||
: ListenSocketBase(port, addr, "servers", Hook), Utils(u)
|
||||
{
|
||||
}
|
||||
|
||||
std::string Hook;
|
||||
|
||||
virtual void OnAcceptReady(int nfd);
|
||||
};
|
||||
|
||||
@ -85,9 +83,6 @@ class SpanningTreeUtilities : public classbase
|
||||
*/
|
||||
bool quiet_bursts;
|
||||
|
||||
/** Socket bindings for listening sockets
|
||||
*/
|
||||
std::vector<ServerSocketListener *> Bindings;
|
||||
/* Number of seconds that a server can go without ping
|
||||
* before opers are warned of high latency.
|
||||
*/
|
||||
|
@ -144,16 +144,16 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
|
||||
}
|
||||
if (!skip)
|
||||
{
|
||||
ClientListenSocket *ll = new ClientListenSocket(portno, Addr);
|
||||
ClientListenSocket *ll = new ClientListenSocket(portno, Addr, "clients", *Desc ? Desc : "plaintext");
|
||||
if (ll->GetFd() > -1)
|
||||
{
|
||||
bound++;
|
||||
ll->SetDescription(*Desc ? Desc : "plaintext");
|
||||
ports.push_back(ll);
|
||||
}
|
||||
else
|
||||
{
|
||||
failed_ports.push_back(std::make_pair(bind_readable, strerror(errno)));
|
||||
delete ll;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,8 +50,8 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results)
|
||||
if (ip.empty())
|
||||
ip.assign("*");
|
||||
|
||||
results.push_back(sn+" 249 "+user->nick+" :"+ ip + ":"+ConvToStr(this->ports[i]->GetPort())+" (client, " +
|
||||
this->ports[i]->GetDescription() + ")");
|
||||
results.push_back(sn+" 249 "+user->nick+" :"+ ip + ":"+ConvToStr(ports[i]->bind_port)+
|
||||
" (" + ports[i]->type + ", " + ports[i]->hook + ")");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user