-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
+ *
+ * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
*
- * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
- *
- * Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
* the file COPYING for details.
*
#include "inspircd.h"
#include "wildcard.h"
#include "xline.h"
-#include "aes.h"
+#include "transport.h"
/** If you make a change which breaks the protocol, increment this.
* If you completely change the protocol, completely change the number.
* Failure to document your protocol changes will result in a painfully
* painful death by pain. You have been warned.
*/
-const long ProtocolVersion = 1102;
+const long ProtocolVersion = 1103;
/*
* The server list in InspIRCd is maintained as two structures
class TreeSocket;
class Link;
class ModuleSpanningTree;
+class SpanningTreeUtilities;
/* This hash_map holds the hash equivalent of the server
* tree, used for rapid linear lookups.
typedef std::map<TreeServer*,TreeServer*> TreeServerList;
+/** A group of modules that implement InspSocketHook
+ * that we can use to hook our server to server connections.
+ */
+typedef std::map<irc::string, Module*> hookmodules;
+
/** The Link class might as well be a struct,
* but this is C++ and we don't believe in structs (!).
* It holds the entire information of one <link>
std::string RecvPass;
unsigned long AutoConnect;
time_t NextConnectTime;
- std::string EncryptionKey;
bool HiddenFromStats;
std::string FailOver;
+ std::string Hook;
int Timeout;
};
+class HandshakeTimer : public InspTimer
+{
+ private:
+ InspIRCd* Instance;
+ TreeSocket* sock;
+ Link* lnk;
+ SpanningTreeUtilities* Utils;
+ int thefd;
+ public:
+ HandshakeTimer(InspIRCd* Inst, TreeSocket* s, Link* l, SpanningTreeUtilities* u);
+ virtual void Tick(time_t TIME);
+};
+
+
/** Contains helper functions and variables for this module,
* and keeps them out of the global namespace
*/
/** Holds the data from the <link> tags in the conf
*/
std::vector<Link> LinkBlocks;
+ /** Holds a bitmask of queued xline types waiting to be applied.
+ * Will be a mask containing values APPLY_GLINES, APPLY_KLINES,
+ * APPLY_QLINES and APPLY_ZLINES.
+ */
+ int lines_to_apply;
+
+ hookmodules hooks;
+ std::vector<std::string> hooknames;
/** Initialise utility class
*/
ServerInstance->Log(DEBUG,"Removing all users from server %s",this->ServerName.c_str());
const char* reason_s = reason.c_str();
std::vector<userrec*> time_to_die;
- for (user_hash::iterator n = ServerInstance->clientlist.begin(); n != ServerInstance->clientlist.end(); n++)
+ for (user_hash::iterator n = ServerInstance->clientlist->begin(); n != ServerInstance->clientlist->end(); n++)
{
if (!strcmp(n->second->server, this->ServerName.c_str()))
{
cmd_rconnect (InspIRCd* Instance, Module* Callback, SpanningTreeUtilities* Util) : command_t(Instance, "RCONNECT", 'o', 2), Creator(Callback), Utils(Util)
{
this->source = "m_spanningtree.so";
- syntax = "<remote-server-mask> <servermask>";
+ syntax = "<remote-server-mask> <target-server-mask>";
}
CmdResult Handle (const char** parameters, int pcnt, userrec *user)
{
- user->WriteServ("NOTICE %s :*** RCONNECT: Sending remote connect to \002%s\002 to connect server \002%s\002.",user->nick,parameters[0],parameters[1]);
+ if (IS_LOCAL(user))
+ {
+ if (!Utils->FindServer(parameters[0]))
+ {
+ user->WriteServ("NOTICE %s :*** RCONNECT: Server \002%s\002 isn't connected to the network!", user->nick, parameters[0]);
+ return CMD_FAILURE;
+ }
+
+ user->WriteServ("NOTICE %s :*** RCONNECT: Sending remote connect to \002%s\002 to connect server \002%s\002.",user->nick,parameters[0],parameters[1]);
+ }
+
/* Is this aimed at our server? */
if (ServerInstance->MatchText(ServerInstance->Config->ServerName,parameters[0]))
{
para[0] = parameters[1];
std::string original_command = std::string("CONNECT ") + parameters[1];
Creator->OnPreCommand("CONNECT", para, 1, user, true, original_command);
-
- return CMD_SUCCESS;
}
-
- return CMD_FAILURE;
+
+ return CMD_SUCCESS;
}
};
time_t NextPing;
bool LastPingWasGood;
bool bursting;
- AES* ctx_in;
- AES* ctx_out;
unsigned int keylength;
std::string ModuleList;
std::map<std::string,std::string> CapKeys;
+ Module* Hook;
public:
* most of the action, and append a few of our own values
* to it.
*/
- TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string host, int port, bool listening, unsigned long maxtime)
- : InspSocket(SI, host, port, listening, maxtime), Utils(Util)
+ TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string host, int port, bool listening, unsigned long maxtime, Module* HookMod = NULL)
+ : InspSocket(SI, host, port, listening, maxtime), Utils(Util), Hook(HookMod)
{
myhost = host;
this->LinkState = LISTENER;
- this->ctx_in = NULL;
- this->ctx_out = NULL;
+
+ 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)
- : InspSocket(SI, host, port, listening, maxtime), Utils(Util)
+ TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string host, int port, bool listening, unsigned long maxtime, std::string ServerName, Module* HookMod = NULL)
+ : InspSocket(SI, host, port, listening, maxtime), Utils(Util), Hook(HookMod)
{
myhost = ServerName;
this->LinkState = CONNECTING;
- this->ctx_in = NULL;
- this->ctx_out = NULL;
+
+ if (Hook)
+ InspSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
}
/** When a listening socket gives us a new file descriptor,
* we must associate it with a socket without creating a new
* connection. This constructor is used for this purpose.
*/
- TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, int newfd, char* ip)
- : InspSocket(SI, newfd, ip), Utils(Util)
+ TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, int newfd, char* ip, Module* HookMod = NULL)
+ : InspSocket(SI, newfd, ip), Utils(Util), Hook(HookMod)
{
this->LinkState = WAIT_AUTH_1;
- this->ctx_in = NULL;
- this->ctx_out = NULL;
- this->SendCapabilities();
+
+ /* If we have a transport module hooked to the parent, hook the same module to this
+ * socket, and set a timer waiting for handshake before we send CAPAB etc.
+ */
+ if (Hook)
+ {
+ InspSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
+ Instance->Timers->AddTimer(new HandshakeTimer(Instance, this, &(Utils->LinkBlocks[0]), this->Utils));
+ }
+ else
+ {
+ /* Otherwise, theres no lower layer transport in plain TCP/IP,
+ * so just send the capabilities right now.
+ */
+ this->SendCapabilities();
+ }
}
- ~TreeSocket()
+ ServerState GetLinkState()
{
- if (ctx_in)
- DELETE(ctx_in);
- if (ctx_out)
- DELETE(ctx_out);
+ return this->LinkState;
}
- void InitAES(std::string key,std::string SName)
+ Module* GetHook()
{
- if (key == "")
- return;
+ return this->Hook;
+ }
- ctx_in = new AES();
- ctx_out = new AES();
- Instance->Log(DEBUG,"Initialized AES key %s",key.c_str());
- // key must be 16, 24, 32 etc bytes (multiple of 8)
- keylength = key.length();
- if (!(keylength == 16 || keylength == 24 || keylength == 32))
- {
- this->Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Key length for encryptionkey is not 16, 24 or 32 bytes in length!");
- Instance->Log(DEBUG,"Key length not 16, 24 or 32 characters!");
- }
- else
- {
- if (this->GetState() != I_ERROR)
- {
- this->Instance->SNO->WriteToSnoMask('l',"\2AES\2: Initialized %d bit encryption to server %s",keylength*8,SName.c_str());
- ctx_in->MakeKey(key.c_str(), "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
- \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", keylength, keylength);
- ctx_out->MakeKey(key.c_str(), "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
- \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", keylength, keylength);
- }
- }
+ ~TreeSocket()
+ {
+ if (Hook)
+ InspSocketUnhookRequest(this, (Module*)Utils->Creator, Hook).Send();
}
/** When an outbound connection finishes connecting, we receive
if (x->Name == this->myhost)
{
this->Instance->SNO->WriteToSnoMask('l',"Connection to \2"+myhost+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] started.");
- this->SendCapabilities();
- if (x->EncryptionKey != "")
+
+ if (Hook)
{
- if (!(x->EncryptionKey.length() == 16 || x->EncryptionKey.length() == 24 || x->EncryptionKey.length() == 32))
- {
- this->Instance->SNO->WriteToSnoMask('l',"\2WARNING\2: Your encryption key is NOT 16, 24 or 32 characters in length, encryption will \2NOT\2 be enabled.");
- }
- else
- {
- this->WriteLine(std::string("AES ")+this->Instance->Config->ServerName);
- this->InitAES(x->EncryptionKey,x->Name.c_str());
- }
+ InspSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
+ this->Instance->SNO->WriteToSnoMask('l',"Connection to \2"+myhost+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+x->Hook+"\2");
}
+ else
+ this->SendCapabilities();
+
/* found who we're supposed to be connecting to, send the neccessary gubbins. */
- this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+x->SendPass+" 0 :"+this->Instance->Config->ServerDesc);
+ if (Hook)
+ Instance->Timers->AddTimer(new HandshakeTimer(Instance, this, &(*x), this->Utils));
+ else
+ this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+x->SendPass+" 0 :"+this->Instance->Config->ServerDesc);
+
return true;
}
}
/* Chances are this is a 1.0 FMODE without TS */
if (params.size() < 3)
{
- this->WriteLine("ERROR :Version 1.0 FMODE sent to version 1.1 server");
- return false;
+ /* No modes were in the command, probably a channel with no modes set on it */
+ return true;
}
bool smode = false;
*/
if (ourTS > TS)
{
+ Instance->Log(DEBUG,"************ WE LOST TS COMPARE, DEOPPING EVERYONE ********************* ");
std::deque<std::string> param_list;
/* Lower the TS here */
chan->WriteChannelWithServ(Instance->Config->ServerName,
"NOTICE %s :TS for %s changed from %lu to %lu", chan->name, chan->name, ourTS, TS);
ourTS = TS;
- param_list.push_back(channel);
/* Zap all the privilage modes on our side, if the channel exists here */
if (!created)
{
- this->RemoveStatus(Instance->Config->ServerName, param_list);
+ param_list.push_back(channel);
+ /* Do this first! */
chan->age = TS;
+ this->RemoveStatus(Instance->Config->ServerName, param_list);
}
}
// 0 1 2 3 4 5 6 7
time_t age = atoi(params[0].c_str());
- /* This used to have a pretty craq'y loop doing the same thing,
- * now we just let the STL do the hard work (more efficiently)
- */
- std::string::size_type pos_after_plus = params[5].find_first_not_of('+');
- if (pos_after_plus != std::string::npos)
- params[5] = params[5].substr(pos_after_plus);
-
const char* tempnick = params[1].c_str();
Instance->Log(DEBUG,"Introduce client %s!%s@%s",tempnick,params[4].c_str(),params[2].c_str());
- user_hash::iterator iter = this->Instance->clientlist.find(tempnick);
+ user_hash::iterator iter = this->Instance->clientlist->find(tempnick);
- if (iter != this->Instance->clientlist.end())
+ if (iter != this->Instance->clientlist->end())
{
// nick collision
Instance->Log(DEBUG,"Nick collision on %s!%s@%s: %lu %lu",tempnick,params[4].c_str(),params[2].c_str(),(unsigned long)age,(unsigned long)iter->second->age);
}
userrec* _new = new userrec(this->Instance);
- this->Instance->clientlist[tempnick] = _new;
+ (*(this->Instance->clientlist))[tempnick] = _new;
_new->SetFd(FD_MAGIC_NUMBER);
strlcpy(_new->nick, tempnick,NICKMAX-1);
strlcpy(_new->host, params[2].c_str(),63);
_new->registered = REG_ALL;
_new->signon = age;
+ /*
+ * we need to remove the + from the modestring, so we can do our stuff
+ */
+ std::string::size_type pos_after_plus = params[5].find_first_not_of('+');
+ if (pos_after_plus != std::string::npos)
+ params[5] = params[5].substr(pos_after_plus);
+
+
for (std::string::iterator v = params[5].begin(); v != params[5].end(); v++)
+ {
_new->modes[(*v)-65] = 1;
+ /* For each mode thats set, increase counter */
+ ModeHandler* mh = Instance->Modes->FindMode(*v, MODETYPE_USER);
+ if (mh)
+ mh->ChangeCount(1);
+ }
+
+ /* now we've done with modes processing, put the + back for remote servers */
+ params[5] = "+" + params[5];
#ifdef SUPPORT_IP6LINKS
if (params[6].find_first_of(":") != std::string::npos)
#endif
_new->SetSockAddr(AF_INET, params[6].c_str(), 0);
+ Instance->AddGlobalClone(_new);
+
this->Instance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s!%s@%s [%s]",_new->server,_new->nick,_new->ident,_new->host, _new->GetIPString());
params[7] = ":" + params[7];
- Utils->DoOneToAllButSender(source,"NICK",params,source);
+ Utils->DoOneToAllButSender(source,"NICK", params, source);
// Increment the Source Servers User Count..
TreeServer* SourceServer = Utils->FindServer(source);
std::string buffer;
std::string n = this->Instance->Config->ServerName;
const char* sn = n.c_str();
- int iterations = 0;
+
/* Yes, these arent too nice looking, but they get the job done */
- for (std::vector<ZLine*>::iterator i = Instance->XLines->zlines.begin(); i != Instance->XLines->zlines.end(); i++, iterations++)
+ for (std::vector<ZLine*>::iterator i = Instance->XLines->zlines.begin(); i != Instance->XLines->zlines.end(); i++)
{
snprintf(data,MAXBUF,":%s ADDLINE Z %s %s %lu %lu :%s\r\n",sn,(*i)->ipaddr,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
buffer.append(data);
}
- for (std::vector<QLine*>::iterator i = Instance->XLines->qlines.begin(); i != Instance->XLines->qlines.end(); i++, iterations++)
+ for (std::vector<QLine*>::iterator i = Instance->XLines->qlines.begin(); i != Instance->XLines->qlines.end(); i++)
{
snprintf(data,MAXBUF,":%s ADDLINE Q %s %s %lu %lu :%s\r\n",sn,(*i)->nick,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
buffer.append(data);
}
- for (std::vector<GLine*>::iterator i = Instance->XLines->glines.begin(); i != Instance->XLines->glines.end(); i++, iterations++)
+ for (std::vector<GLine*>::iterator i = Instance->XLines->glines.begin(); i != Instance->XLines->glines.end(); i++)
{
snprintf(data,MAXBUF,":%s ADDLINE G %s@%s %s %lu %lu :%s\r\n",sn,(*i)->identmask,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
buffer.append(data);
}
- for (std::vector<ELine*>::iterator i = Instance->XLines->elines.begin(); i != Instance->XLines->elines.end(); i++, iterations++)
+ for (std::vector<ELine*>::iterator i = Instance->XLines->elines.begin(); i != Instance->XLines->elines.end(); i++)
{
snprintf(data,MAXBUF,":%s ADDLINE E %s@%s %s %lu %lu :%s\r\n",sn,(*i)->identmask,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
buffer.append(data);
}
- for (std::vector<ZLine*>::iterator i = Instance->XLines->pzlines.begin(); i != Instance->XLines->pzlines.end(); i++, iterations++)
+ for (std::vector<ZLine*>::iterator i = Instance->XLines->pzlines.begin(); i != Instance->XLines->pzlines.end(); i++)
{
snprintf(data,MAXBUF,":%s ADDLINE Z %s %s %lu %lu :%s\r\n",sn,(*i)->ipaddr,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
buffer.append(data);
}
- for (std::vector<QLine*>::iterator i = Instance->XLines->pqlines.begin(); i != Instance->XLines->pqlines.end(); i++, iterations++)
+ for (std::vector<QLine*>::iterator i = Instance->XLines->pqlines.begin(); i != Instance->XLines->pqlines.end(); i++)
{
snprintf(data,MAXBUF,":%s ADDLINE Q %s %s %lu %lu :%s\r\n",sn,(*i)->nick,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
buffer.append(data);
}
- for (std::vector<GLine*>::iterator i = Instance->XLines->pglines.begin(); i != Instance->XLines->pglines.end(); i++, iterations++)
+ for (std::vector<GLine*>::iterator i = Instance->XLines->pglines.begin(); i != Instance->XLines->pglines.end(); i++)
{
snprintf(data,MAXBUF,":%s ADDLINE G %s@%s %s %lu %lu :%s\r\n",sn,(*i)->identmask,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
buffer.append(data);
}
- for (std::vector<ELine*>::iterator i = Instance->XLines->pelines.begin(); i != Instance->XLines->pelines.end(); i++, iterations++)
+ for (std::vector<ELine*>::iterator i = Instance->XLines->pelines.begin(); i != Instance->XLines->pelines.end(); i++)
{
snprintf(data,MAXBUF,":%s ADDLINE E %s@%s %s %lu %lu :%s\r\n",sn,(*i)->identmask,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
buffer.append(data);
{
char data[MAXBUF];
std::deque<std::string> list;
- int iterations = 0;
std::string n = this->Instance->Config->ServerName;
const char* sn = n.c_str();
- for (chan_hash::iterator c = this->Instance->chanlist.begin(); c != this->Instance->chanlist.end(); c++, iterations++)
+ for (chan_hash::iterator c = this->Instance->chanlist->begin(); c != this->Instance->chanlist->end(); c++)
{
SendFJoins(Current, c->second);
if (*c->second->topic)
char data[MAXBUF];
std::deque<std::string> list;
std::string dataline;
- int iterations = 0;
- for (user_hash::iterator u = this->Instance->clientlist.begin(); u != this->Instance->clientlist.end(); u++, iterations++)
+ for (user_hash::iterator u = this->Instance->clientlist->begin(); u != this->Instance->clientlist->end(); u++)
{
if (u->second->registered == REG_ALL)
{
/* Process this one, abort if it
* didnt return true.
*/
- if (this->ctx_in)
- {
- char out[1024];
- char result[1024];
- memset(result,0,1024);
- memset(out,0,1024);
- /* ERROR + CAPAB is still allowed unencryped */
- if ((ret.substr(0,7) != "ERROR :") && (ret.substr(0,6) != "CAPAB "))
- {
- int nbytes = from64tobits(out, ret.c_str(), 1024);
- if ((nbytes > 0) && (nbytes < 1024))
- {
- ctx_in->Decrypt(out, result, nbytes, 0);
- for (int t = 0; t < nbytes; t++)
- {
- if (result[t] == '\7')
- {
- /* We only need to stick a \0 on the
- * first \7, the rest will be lost
- */
- result[t] = 0;
- break;
- }
- }
- ret = result;
- }
- }
- }
if (!this->ProcessLine(ret))
{
return false;
int WriteLine(std::string line)
{
Instance->Log(DEBUG,"OUT: %s",line.c_str());
- if (this->ctx_out)
- {
- char result[10240];
- char result64[10240];
- if (this->keylength)
- {
- // pad it to the key length
- int n = this->keylength - (line.length() % this->keylength);
- if (n)
- line.append(n,'\7');
- }
- unsigned int ll = line.length();
- ctx_out->Encrypt(line.c_str(), result, ll, 0);
- to64frombits((unsigned char*)result64,(unsigned char*)result,ll);
- line = result64;
- }
line.append("\r\n");
return this->Write(line);
}
if (u)
{
u->modes[UM_OPERATOR] = 1;
+ this->Instance->all_opers.push_back(u);
strlcpy(u->oper,opertype.c_str(),NICKMAX-1);
Utils->DoOneToAllButSender(u->nick,"OPERTYPE",params,u->server);
+ this->Instance->SNO->WriteToSnoMask('o',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick,u->ident,u->host,irc::Spacify(opertype.c_str()));
+
}
return true;
}
if (u)
{
- chanrec::JoinUser(this->Instance, u, params[1].c_str(), false);
+ /* only join if it's local, otherwise just pass it on! */
+ if (IS_LOCAL(u))
+ chanrec::JoinUser(this->Instance, u, params[1].c_str(), false);
Utils->DoOneToAllButSender(prefix,"SVSJOIN",params,prefix);
}
return true;
if (this->Instance->MatchText(this->Instance->Config->ServerName,servermask))
{
- this->Instance->SNO->WriteToSnoMask('l',"Remote rehash initiated from server \002"+prefix+"\002.");
+ this->Instance->SNO->WriteToSnoMask('l',"Remote rehash initiated by \002"+prefix+"\002.");
this->Instance->RehashServer();
Utils->ReadConfiguration(false);
InitializeDisabledCommands(Instance->Config->DisabledCommands, Instance);
bool propogate = false;
+ if (!this->bursting)
+ Utils->lines_to_apply = 0;
+
switch (*(params[0].c_str()))
{
case 'Z':
propogate = Instance->XLines->add_zline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
Instance->XLines->zline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
+ if (propogate)
+ Utils->lines_to_apply |= APPLY_ZLINES;
break;
case 'Q':
propogate = Instance->XLines->add_qline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
Instance->XLines->qline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
+ if (propogate)
+ Utils->lines_to_apply |= APPLY_QLINES;
break;
case 'E':
propogate = Instance->XLines->add_eline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
case 'G':
propogate = Instance->XLines->add_gline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
Instance->XLines->gline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
+ if (propogate)
+ Utils->lines_to_apply |= APPLY_GLINES;
break;
case 'K':
propogate = Instance->XLines->add_kline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
+ if (propogate)
+ Utils->lines_to_apply |= APPLY_KLINES;
break;
default:
/* Just in case... */
}
if (!this->bursting)
{
- Instance->Log(DEBUG,"Applying lines...");
- Instance->XLines->apply_lines(APPLY_ZLINES|APPLY_GLINES|APPLY_QLINES);
+ Instance->Log(DEBUG,"Applying lines with mask %d...", Utils->lines_to_apply);
+ Instance->XLines->apply_lines(Utils->lines_to_apply);
+ Utils->lines_to_apply = 0;
}
return true;
}
this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
return false;
}
- /* If the config says this link is encrypted, but the remote side
- * hasnt bothered to send the AES command before SERVER, then we
- * boot them off as we MUST have this connection encrypted.
- */
- if ((x->EncryptionKey != "") && (!this->ctx_in))
+ this->Instance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] ("+description+")");
+
+ if (this->Hook)
{
- this->WriteLine("ERROR :This link requires AES encryption to be enabled. Plaintext connection refused.");
- this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, remote server did not enable AES.");
- return false;
+ std::string name = InspSocketNameRequest((Module*)Utils->Creator, this->Hook).Send();
+ this->Instance->SNO->WriteToSnoMask('l',"Connection from \2"+sname+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+name+"\2");
}
- this->Instance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] ("+description+")");
+
this->InboundServerName = sname;
this->InboundDescription = description;
// this is good. Send our details: Our server name and description and hopcount of 0,
command = params[0].c_str();
params.pop_front();
- if ((!this->ctx_in) && (command == "AES"))
- {
- std::string sserv = params[0];
- for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
- {
- if ((x->EncryptionKey != "") && (x->Name == sserv))
- {
- this->InitAES(x->EncryptionKey,sserv);
- }
- }
-
- return true;
- }
- else if ((this->ctx_in) && (command == "AES"))
- {
- this->Instance->SNO->WriteToSnoMask('l',"\2AES\2: Encryption already enabled on this connection yet %s is trying to enable it twice!",params[0].c_str());
- }
-
switch (this->LinkState)
{
TreeServer* Node;
if (this->bursting)
{
this->bursting = false;
- Instance->XLines->apply_lines(APPLY_ZLINES|APPLY_GLINES|APPLY_QLINES);
+ Instance->Log(DEBUG,"Applying lines with mask %d...", Utils->lines_to_apply);
+ Instance->XLines->apply_lines(Utils->lines_to_apply);
+ Utils->lines_to_apply = 0;
}
if (prefix == "")
{
if (this->bursting)
{
this->bursting = false;
- Instance->XLines->apply_lines(APPLY_ZLINES|APPLY_GLINES|APPLY_QLINES);
+ Instance->Log(DEBUG,"Applying lines with mask %d...", Utils->lines_to_apply);
+ Instance->XLines->apply_lines(Utils->lines_to_apply);
+ Utils->lines_to_apply = 0;
}
if (prefix == "")
{
else if (command == "ENDBURST")
{
this->bursting = false;
- Instance->XLines->apply_lines(APPLY_ZLINES|APPLY_GLINES|APPLY_QLINES);
+ Instance->Log(DEBUG,"Applying lines with mask %d...", Utils->lines_to_apply);
+ Instance->XLines->apply_lines(Utils->lines_to_apply);
+ Utils->lines_to_apply = 0;
std::string sourceserv = this->myhost;
if (this->InboundServerName != "")
{
return false;
}
}
- TreeSocket* s = new TreeSocket(this->Utils, this->Instance, newsock, ip);
+
+ TreeSocket* s = new TreeSocket(this->Utils, this->Instance, newsock, ip, this->Hook);
+
s = s; /* Whinge whinge whinge, thats all GCC ever does. */
return true;
}
Link MyLink;
SpanningTreeUtilities* Utils;
public:
- ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, me), MyLink(x), Utils(Util)
+ ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), MyLink(x), Utils(Util)
{
/* Nothing in here, folks */
}
- void OnLookupComplete(const std::string &result)
+ void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
/* Initiate the connection, now that we have an IP to use.
* Passing a hostname directly to InspSocket causes it to
TreeServer* CheckDupe = Utils->FindServer(MyLink.Name.c_str());
if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
{
- TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,false,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str());
+
+ if ((!MyLink.Hook.empty()) && (Utils->hooks.find(MyLink.Hook.c_str()) == Utils->hooks.end()))
+ return;
+
+ TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,false,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str(),
+ MyLink.Hook.empty() ? NULL : Utils->hooks[MyLink.Hook.c_str()]);
if (newsocket->GetFd() > -1)
{
/* We're all OK */
Link MyLink;
SpanningTreeUtilities* Utils;
public:
- SecurityIPResolver(Module* me, SpanningTreeUtilities* U, InspIRCd* Instance, const std::string &hostname, Link x) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, me), MyLink(x), Utils(U)
+ SecurityIPResolver(Module* me, SpanningTreeUtilities* U, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), MyLink(x), Utils(U)
{
}
- void OnLookupComplete(const std::string &result)
+ void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
{
ServerInstance->Log(DEBUG,"Security IP cache: Adding IP address '%s' for Link '%s'",result.c_str(),MyLink.Name.c_str());
Utils->ValidIPs.push_back(result);
SpanningTreeUtilities::SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* C) : ServerInstance(Instance), Creator(C)
{
Bindings.clear();
- this->ReadConfiguration(true);
+
+ lines_to_apply = 0;
+
this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc);
+
+ modulelist* ml = ServerInstance->FindInterface("InspSocketHook");
+
+ /* Did we find any modules? */
+ if (ml)
+ {
+ /* Yes, enumerate them all to find out the hook name */
+ for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
+ {
+ /* Make a request to it for its name, its implementing
+ * InspSocketHook so we know its safe to do this
+ */
+ std::string name = InspSocketNameRequest((Module*)Creator, *m).Send();
+ /* Build a map of them */
+ hooks[name.c_str()] = *m;
+ hooknames.push_back(name);
+ ServerInstance->Log(DEBUG, "Found InspSocketHook interface: '%s' -> '%08x'", name.c_str(), *m);
+ }
+ }
+
+ this->ReadConfiguration(true);
}
SpanningTreeUtilities::~SpanningTreeUtilities()
std::string Type = Conf->ReadValue("bind","type",j);
std::string IP = Conf->ReadValue("bind","address",j);
std::string Port = Conf->ReadValue("bind","port",j);
+ std::string transport = Conf->ReadValue("bind","transport",j);
if (Type == "servers")
{
irc::portparser portrange(Port, false);
if (IP == "*")
IP = "";
- TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10);
+ if ((!transport.empty()) && (hooks.find(transport.c_str()) == hooks.end()))
+ {
+ ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for port %s:%s - maybe you forgot to load it BEFORE m_spanningtree in your config file? - Skipping this port binding",
+ transport.c_str(), IP.c_str(), Port.c_str());
+ break;
+ }
+
+ TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
if (listener->GetState() == I_LISTENING)
{
ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
L.SendPass = Conf->ReadValue("link","sendpass",j);
L.RecvPass = Conf->ReadValue("link","recvpass",j);
L.AutoConnect = Conf->ReadInteger("link","autoconnect",j,true);
- L.EncryptionKey = Conf->ReadValue("link","encryptionkey",j);
L.HiddenFromStats = Conf->ReadFlag("link","hidden",j);
L.Timeout = Conf->ReadInteger("link","timeout",j,true);
+ L.Hook = Conf->ReadValue("link", "transport", j);
+
+ if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) == hooks.end()))
+ {
+ ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for link '%s' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.",
+ L.Hook.c_str(), L.Name.c_str());
+ continue;
+
+ }
+
L.NextConnectTime = time(NULL) + L.AutoConnect;
/* Bugfix by brain, do not allow people to enter bad configurations */
if (L.Name != ServerInstance->Config->ServerName)
{
try
{
- SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L);
- ServerInstance->AddResolver(sr);
+ bool cached;
+ SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached);
+ ServerInstance->AddResolver(sr, cached);
}
catch (ModuleException& e)
{
virtual void Tick(time_t TIME);
};
+HandshakeTimer::HandshakeTimer(InspIRCd* Inst, TreeSocket* s, Link* l, SpanningTreeUtilities* u) : InspTimer(1, time(NULL)), Instance(Inst), sock(s), lnk(l), Utils(u)
+{
+ thefd = sock->GetFd();
+}
+
+void HandshakeTimer::Tick(time_t TIME)
+{
+ if (Instance->SE->GetRef(thefd) == sock)
+ {
+ if (sock->GetHook() && InspSocketHSCompleteRequest(sock, (Module*)Utils->Creator, sock->GetHook()).Send())
+ {
+ Instance->Log(DEBUG,"Handshake timer activated, sending SERVER and/or CAPAB");
+ InspSocketAttachCertRequest(sock, (Module*)Utils->Creator, sock->GetHook()).Send();
+ sock->SendCapabilities();
+ if (sock->GetLinkState() == CONNECTING)
+ {
+ sock->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+lnk->SendPass+" 0 :"+this->Instance->Config->ServerDesc);
+ }
+ }
+ else
+ {
+ Instance->Timers->AddTimer(new HandshakeTimer(Instance, sock, lnk, Utils));
+ }
+ }
+}
+
class ModuleSpanningTree : public Module
{
int line;
ModuleSpanningTree(InspIRCd* Me)
: Module::Module(Me), max_local(0), max_global(0)
{
+ ServerInstance->UseInterface("InspSocketHook");
+
Utils = new SpanningTreeUtilities(Me, this);
command_rconnect = new cmd_rconnect(ServerInstance, this, Utils);
float percent;
char text[80];
- if (ServerInstance->clientlist.size() == 0) {
+ if (ServerInstance->clientlist->size() == 0) {
// If there are no users, WHO THE HELL DID THE /MAP?!?!?!
percent = 0;
}
else
{
- percent = ((float)Current->GetUserCount() / (float)ServerInstance->clientlist.size()) * 100;
+ percent = ((float)Current->GetUserCount() / (float)ServerInstance->clientlist->size()) * 100;
}
snprintf(text, 80, "%s %s%5d [%5.2f%%]", Current->GetName().c_str(), spacer, Current->GetUserCount(), percent);
totusers += Current->GetUserCount();
/* Do we already have an IP? If so, no need to resolve it. */
if (insp_aton(x->IPAddr.c_str(), &binip) > 0)
{
- TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port,false,x->Timeout ? x->Timeout : 10,x->Name.c_str());
+ /* Gave a hook, but it wasnt one we know */
+ if ((!x->Hook.empty()) && (Utils->hooks.find(x->Hook.c_str()) == Utils->hooks.end()))
+ return;
+
+ TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port,false,x->Timeout ? x->Timeout : 10,x->Name.c_str(), x->Hook.empty() ? NULL : Utils->hooks[x->Hook.c_str()]);
if (newsocket->GetFd() > -1)
{
/* Handled automatically on success */
{
try
{
- ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x);
- ServerInstance->AddResolver(snr);
+ bool cached;
+ ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x, cached);
+ ServerInstance->AddResolver(snr, cached);
}
catch (ModuleException& e)
{
user->WriteServ("351 %s :%s",user->nick,Version.c_str());
if (found == Utils->TreeRoot)
{
- std::stringstream out(ServerInstance->Config->data005);
- std::string token = "";
- std::string line5 = "";
- int token_counter = 0;
-
- while (!out.eof())
- {
- out >> token;
- line5 = line5 + token + " ";
- token_counter++;
-
- if ((token_counter >= 13) || (out.eof() == true))
- {
- user->WriteServ("005 %s %s:are supported by this server",user->nick,line5.c_str());
- line5 = "";
- token_counter = 0;
- }
- }
+ ServerInstance->Config->Send005(user);
}
}
else
{
for (unsigned int i = 0; i < Utils->LinkBlocks.size(); i++)
{
- results.push_back(std::string(ServerInstance->Config->ServerName)+" 213 "+user->nick+" "+statschar+" *@"+(Utils->LinkBlocks[i].HiddenFromStats ? "<hidden>" : Utils->LinkBlocks[i].IPAddr)+" * "+Utils->LinkBlocks[i].Name.c_str()+" "+ConvToStr(Utils->LinkBlocks[i].Port)+" "+(Utils->LinkBlocks[i].EncryptionKey != "" ? 'e' : '-')+(Utils->LinkBlocks[i].AutoConnect ? 'a' : '-')+'s');
+ results.push_back(std::string(ServerInstance->Config->ServerName)+" 213 "+user->nick+" "+statschar+" *@"+(Utils->LinkBlocks[i].HiddenFromStats ? "<hidden>" : Utils->LinkBlocks[i].IPAddr)+" * "+Utils->LinkBlocks[i].Name.c_str()+" "+ConvToStr(Utils->LinkBlocks[i].Port)+" "+(Utils->LinkBlocks[i].Hook.empty() ? "plaintext" : Utils->LinkBlocks[i].Hook)+" "+(Utils->LinkBlocks[i].AutoConnect ? 'a' : '-')+'s');
if (statschar == 'c')
results.push_back(std::string(ServerInstance->Config->ServerName)+" 244 "+user->nick+" H * * "+Utils->LinkBlocks[i].Name.c_str());
}
// Only do this for local users
if (IS_LOCAL(user))
{
- std::deque<std::string> params;
- params.clear();
- params.push_back(channel->name);
- // set up their permissions and the channel TS with FJOIN.
- // All users are FJOINed now, because a module may specify
- // new joining permissions for the user.
- params.clear();
- params.push_back(channel->name);
- params.push_back(ConvToStr(channel->age));
- params.push_back(std::string(channel->GetAllPrefixChars(user))+","+std::string(user->nick));
- Utils->DoOneToMany(ServerInstance->Config->ServerName,"FJOIN",params);
if (channel->GetUserCounter() == 1)
{
+ std::deque<std::string> params;
+ // set up their permissions and the channel TS with FJOIN.
+ // All users are FJOINed now, because a module may specify
+ // new joining permissions for the user.
+ params.push_back(channel->name);
+ params.push_back(ConvToStr(channel->age));
+ params.push_back(std::string(channel->GetAllPrefixChars(user))+","+std::string(user->nick));
+ Utils->DoOneToMany(ServerInstance->Config->ServerName,"FJOIN",params);
/* First user in, sync the modes for the channel */
params.pop_back();
/* This is safe, all inspircd servers default to +nt */
params.push_back("+nt");
Utils->DoOneToMany(ServerInstance->Config->ServerName,"FMODE",params);
}
+ else
+ {
+ std::deque<std::string> params;
+ params.push_back(channel->name);
+ params.push_back(ConvToStr(channel->age));
+ Utils->DoOneToMany(user->nick,"JOIN",params);
+ }
}
}
Utils->DoOneToMany(source->nick,"KILL",params);
}
- virtual void OnRehash(const std::string ¶meter)
+ virtual void OnRehash(userrec* user, const std::string ¶meter)
{
if (parameter != "")
{
std::deque<std::string> params;
params.push_back(parameter);
- Utils->DoOneToMany(ServerInstance->Config->ServerName,"REHASH",params);
+ Utils->DoOneToMany(user ? user->nick : ServerInstance->Config->ServerName, "REHASH", params);
// check for self
if (ServerInstance->MatchText(ServerInstance->Config->ServerName,parameter))
{
- ServerInstance->WriteOpers("*** Remote rehash initiated from server \002%s\002",ServerInstance->Config->ServerName);
+ ServerInstance->WriteOpers("*** Remote rehash initiated locally by \002%s\002", user ? user->nick : ServerInstance->Config->ServerName);
ServerInstance->RehashServer();
}
}
Utils->ReadConfiguration(false);
+ InitializeDisabledCommands(ServerInstance->Config->DisabledCommands, ServerInstance);
}
// note: the protocol does not allow direct umode +o except
delete Utils;
if (SyncTimer)
ServerInstance->Timers->DelTimer(SyncTimer);
+
+ ServerInstance->DoneWithInterface("InspSocketHook");
}
virtual Version GetVersion()
}
};
-TimeSyncTimer::TimeSyncTimer(InspIRCd *Inst, ModuleSpanningTree *Mod) : InspTimer(43200, Inst->Time()), Instance(Inst), Module(Mod)
+TimeSyncTimer::TimeSyncTimer(InspIRCd *Inst, ModuleSpanningTree *Mod) : InspTimer(43200, Inst->Time(), true), Instance(Inst), Module(Mod)
{
}
void TimeSyncTimer::Tick(time_t TIME)
{
Module->BroadcastTimeSync();
- Module->SyncTimer = new TimeSyncTimer(Instance, Module);
- Instance->Timers->AddTimer(Module->SyncTimer);
}
void SpanningTreeUtilities::DoFailOver(Link* x)