diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-11-25 10:35:27 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-11-25 10:35:27 +0000 |
commit | e4381d273adcf98b3bfab6827617c46d962c3b3a (patch) | |
tree | a1efc960c9c7042a1a4c050819fde54b249ea38a /src | |
parent | de094dc10486d380e692fec970cb01ccd33ded41 (diff) |
Removed cross-server mesh stuff
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1935 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.cpp | 1865 |
1 files changed, 0 insertions, 1865 deletions
diff --git a/src/commands.cpp b/src/commands.cpp index d2678e2b9..d61c77f74 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1524,138 +1524,17 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } -void ConnectServer(char* servermask,userrec* user) -{ - char Link_ServerName[1024]; - char Link_IPAddr[1024]; - char Link_Port[1024]; - char Link_Pass[1024]; - int LinkPort; - bool found = false; - - for (int i = 0; i < ConfValueEnum("link",&config_f); i++) - { - if (!found) - { - ConfValue("link","name",i,Link_ServerName,&config_f); - ConfValue("link","ipaddr",i,Link_IPAddr,&config_f); - ConfValue("link","port",i,Link_Port,&config_f); - ConfValue("link","sendpass",i,Link_Pass,&config_f); - LinkPort = atoi(Link_Port); - if (match(Link_ServerName,servermask)) { - found = true; - break; - } - } - } - - if (!found) { - if (user) - WriteServ(user->fd,"NOTICE %s :*** Failed to connect to %s: No servers matching this pattern are configured for linking.",user->nick,servermask); - return; - } - - if (user) - { - WriteServ(user->fd,"NOTICE %s :*** Connecting to %s (%s) port %s...",user->nick,Link_ServerName,Link_IPAddr,Link_Port); - } - else WriteOpers("*** Autoconnecting to %s (%s) port %s...",Link_ServerName,Link_IPAddr,Link_Port); - - if (me[defaultRoute]) - { - me[defaultRoute]->BeginLink(Link_IPAddr,LinkPort,Link_Pass,Link_ServerName,me[defaultRoute]->port); - return; - } - else - { - if (user) - WriteServ(user->fd,"NOTICE %s :No default route is defined for server connections on this server. You must define a server connection to be default route so that sockets can be bound to it.",user->nick); - } -} - - void handle_connect(char **parameters, int pcnt, userrec *user) { - ConnectServer(parameters[0],user); } void handle_squit(char **parameters, int pcnt, userrec *user) { - // send out an squit across the mesh and then clear the server list (for local squit) - if (!pcnt) - { - WriteOpers("SQUIT command issued by %s",user->nick); - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"& %s",ServerName); - NetSendToAll(buffer); - DoSplitEveryone(); - } - else - { - if (!strcasecmp("*",parameters[0])) - { - WriteServ(user->fd,"NOTICE %s :*** You cannot issue an SQUIT this wide! If this is REALLY what you want, use a less wide mask.",user->nick); - WriteOpers("*** WARNING! %s tried to SQUIT all servers at once!",user->nick); - return; - } - if (!strcasecmp(ServerName,parameters[0])) - { - WriteServ(user->fd,"NOTICE %s :*** To take the local server out of the mesh, just use /SQUIT with no parameters instead.",user->nick); - return; - } - bool have_this_server = true; - int n_count = 0; - std::string server_to_squit = ""; - while (have_this_server) - { - have_this_server = false; - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int x = 0; x < me[j]->connectors.size(); x++) - { - if (match(me[j]->connectors[x].GetServerName().c_str(),parameters[0])) - { - // found a valid ircd_connector. - have_this_server = true; - server_to_squit = me[j]->connectors[x].GetServerName().c_str(); - break; - } - } - } - } - if (have_this_server) - { - WriteOpers("SQUIT command issued by %s to remove %s from the mesh",user->nick,server_to_squit.c_str()); - WriteServ(user->fd,"NOTICE %s :*** Removing remote server %s.",user->nick,server_to_squit.c_str()); - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"& %s",server_to_squit.c_str()); - NetSendToAll(buffer); - DoSplit(server_to_squit.c_str()); - n_count++; - } - } - if (!n_count) - { - WriteServ(user->fd,"402 %s %s :Your pattern did not match any servers.",user->nick,parameters[0]); - } - } } void handle_links(char **parameters, int pcnt, userrec *user) { WriteServ(user->fd,"364 %s %s %s :0 %s",user->nick,ServerName,ServerName,ServerDesc); - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int k = 0; k < me[j]->connectors.size(); k++) - { - WriteServ(user->fd,"364 %s %s %s :1 %s",user->nick,me[j]->connectors[k].GetServerName().c_str(),ServerName,me[j]->connectors[k].GetDescription().c_str()); - } - } - } WriteServ(user->fd,"365 %s * :End of /LINKS list.",user->nick); } @@ -1663,23 +1542,6 @@ void handle_map(char **parameters, int pcnt, userrec *user) { char line[MAXBUF]; snprintf(line,MAXBUF,"006 %s :%s",user->nick,ServerName); - while (strlen(line) < 50) - strcat(line," "); - WriteServ(user->fd,"%s%d (%.2f%%)",line,local_count(),(float)(((float)local_count()/(float)registered_usercount())*100)); - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int k = 0; k < me[j]->connectors.size(); k++) - { - int state = me[j]->connectors[k].GetState(); - snprintf(line,MAXBUF,"006 %s :%c%s%s",user->nick,islast(me[j]->connectors[k].GetServerName().c_str()),state == STATE_NOAUTH_INBOUND || state == STATE_NOAUTH_OUTBOUND ? "-*" : "--", me[j]->connectors[k].GetServerName().c_str()); - while (strlen(line) < 50) - strcat(line," "); - WriteServ(user->fd,"%s%d (%.2f%%)",line,map_count(me[j]->connectors[k].GetServerName().c_str()),(float)(((float)map_count(me[j]->connectors[k].GetServerName().c_str())/(float)registered_usercount())*100)); - } - } - } WriteServ(user->fd,"007 %s :End of /MAP",user->nick); } @@ -1903,1733 +1765,6 @@ void handle_nick(char **parameters, int pcnt, userrec *user) } } -void handle_equals(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* servername = strtok(params," "); - char* descr = strtok(NULL,"\r\n"); - - if ((!servername) || (!descr)) - return; - - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int x = 0; x < me[j]->connectors.size(); x++) - { - if (!strcasecmp(me[j]->connectors[x].GetServerName().c_str(),servername)) - { - me[j]->connectors[x].SetDescription(descr); - } - } - } - } -} - - -void handle_v(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* servername = strtok(params," "); - char* versionstr = strtok(NULL,"\r\n"); - - if ((!servername) || (!versionstr)) - return; - - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int x = 0; x < me[j]->connectors.size(); x++) - { - if (!strcasecmp(me[j]->connectors[x].GetServerName().c_str(),servername)) - { - me[j]->connectors[x].SetVersionString(versionstr); - WriteOpers("Server '%s' (%d:%d) announces itself as version '%s'",me[j]->connectors[x].GetServerName().c_str(),j,x,me[j]->connectors[x].GetVersionString().c_str()); - } - } - } - } -} - -void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* src = strtok(params," "); - char* dest = strtok(NULL," :"); - char* text = strtok(NULL,"\r\n"); - - if ((!src) || (!dest) || (!text)) - return; - - text++; - - userrec* user = Find(src); - if (user) - { - // notice all - only issuable by a server - if (!strcmp(dest,"*")) - { - NoticeAll(user,true,"%s",text); - } - if (!strcmp(dest,"@*")) - { - NoticeAllOpers(user,true,"%s",text); - } - else - { - userrec* dst = Find(dest); - if (dst) - { - WriteTo(user, dst, "NOTICE %s :%s", dst->nick, text); - } - else - { - chanrec* d = FindChan(dest); - if (d) - { - ChanExceptSender(d, user, "NOTICE %s :%s", d->name, text); - } - } - } - } - -} - - -void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* src = strtok(params," "); - char* dest = strtok(NULL," :"); - char* text = strtok(NULL,"\r\n"); - - if ((!src) || (!dest) || (!text)) - return; - - text++; - - userrec* user = Find(src); - if (user) - { - userrec* dst = Find(dest); - - if (dst) - { - WriteTo(user, dst, "PRIVMSG %s :%s", dst->nick, text); - } - else - { - chanrec* d = FindChan(dest); - if (d) - { - ChanExceptSender(d, user, "PRIVMSG %s :%s", d->name, text); - } - } - } - -} - -void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* nick = strtok(params," "); - char* from = strtok(NULL," "); - char* channel = strtok(NULL," "); - - if ((!nick) || (!from) || (!channel)) - return; - - userrec* u = Find(nick); - userrec* user = Find(from); - chanrec* c = FindChan(channel); - if ((c) && (u) && (user)) - { - u->InviteTo(c->name); - WriteFrom(u->fd,user,"INVITE %s :%s",u->nick,c->name); - } -} - -void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* setby = strtok(params," "); - char* channel = strtok(NULL," :"); - char* topic = strtok(NULL,"\r\n"); - - if ((!setby) || (!channel) || (!topic)) - return; - - topic++; - userrec* u = Find(setby); - chanrec* c = FindChan(channel); - if ((c) && (u)) - { - WriteChannelLocal(c,u,"TOPIC %s :%s",c->name,topic); - strlcpy(c->topic,topic,MAXTOPIC); - strlcpy(c->setby,u->nick,NICKMAX); - c->topicset = TIME; - } -} - - -void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* tm = strtok(params," "); - char* setby = strtok(NULL," "); - char* channel = strtok(NULL," :"); - char* topic = strtok(NULL,"\r\n"); - - if ((!tm) || (!setby) || (!channel) || (!topic)) - return; - - topic++; - time_t TS = atoi(tm); - chanrec* c = FindChan(channel); - if (c) - { - // in the case of topics and TS, the *NEWER* - if (TS <= c->topicset) - { - WriteChannelLocal(c,NULL,"TOPIC %s :%s",c->name,topic); - strlcpy(c->topic,topic,MAXTOPIC); - strlcpy(c->setby,setby,NICKMAX); - } - } -} - -void handle_M(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* pars[128]; - char original[MAXBUF],target[MAXBUF]; - strlcpy(original,params,MAXBUF); - int index = 0; - char* parameter = strtok(params," "); - - if (!parameter) - return; - - strlcpy(target,parameter,MAXBUF); - while (parameter) - { - if (parameter[0] == ':') - parameter++; - pars[index++] = parameter; - parameter = strtok(NULL," "); - } - log(DEBUG,"*** MODE: '%s %s'",pars[0],pars[1]); - merge_mode(pars,index); - if (FindChan(target)) - { - WriteChannelLocal(FindChan(target), NULL, "MODE %s",original); - return; - } - if (Find(target)) - { - if (original[0]) - Write(Find(target)->fd,":%s MODE %s",ServerName,original); - } -} - -// m is modes set by users only (not servers) valid targets are channels or users. - -void handle_m(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - // m blah #chatspike +b *!test@*4 - char* pars[128]; - char original[MAXBUF]; - - if (!params) - return; - - strlcpy(original,params,MAXBUF); - - if (!strchr(params,' ')) - { - WriteOpers("WARNING! 'm' token in data stream without any parameters! Something fishy is going on!"); - return; - } - - int index = 0; - - char* src = strtok(params," "); - - if (!src) - return; - - userrec* user = Find(src); - - if (user) - { - log(DEBUG,"Found user: %s",user->nick); - char* parameter = strtok(NULL," "); - while (parameter) - { - pars[index++] = parameter; - parameter = strtok(NULL," "); - } - - log(DEBUG,"Calling merge_mode2"); - if (index) - merge_mode2(pars,index,user); - } -} - - -void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* nick = NULL; - char* channel = NULL; - char* reason = NULL; - log(DEBUG,"L TOKEN PARS: '%s'",params); - if (strstr(params,":#")) - { - nick = strtok(params," "); - channel = strtok(NULL,"\r\n"); - if ((!nick) || (!channel)) - return; - channel++; - reason = ""; - } - else - { - nick = strtok(params," "); - channel = strtok(NULL," :"); - reason = strtok(NULL,"\r\n"); - if ((!nick) || (!channel) || (!reason)) - return; - reason++; - } - userrec* user = Find(nick); - if ((user) && (channel) && (reason)) - { - if ((!reason) && (*reason != '\0')) - { - del_channel(user,channel,reason,true); - } - else - { - del_channel(user,channel,NULL,true); - } - } -} - -void handle_K(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* src = strtok(params," "); - char* nick = strtok(NULL," :"); - char* reason = strtok(NULL,"\r\n"); - if ((!src) || (!nick) || (!reason)) - return; - char kreason[MAXBUF]; - reason++; - - userrec* u = Find(nick); - userrec* user = Find(src); - - if ((user) && (u)) - { - WriteTo(user, u, "KILL %s :%s!%s!%s!%s (%s)", u->nick, tcp_host, ServerName, user->dhost,user->nick,reason); - WriteOpers("*** Remote kill from %s by %s: %s!%s@%s (%s)",tcp_host,user->nick,u->nick,u->ident,u->host,reason); - snprintf(kreason,MAXBUF,"[%s] Killed (From: '%s' (%s))",tcp_host,user->nick,reason); - kill_link(u,kreason); - } -} - -void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* nick = strtok(params," :"); - char* reason = strtok(NULL,"\r\n"); - - if ((!nick) || (!reason)) - return; - reason++; - - userrec* user = Find(nick); - - if (user) - { - if (strlen(reason)>MAXQUIT) - { - reason[MAXQUIT-1] = '\0'; - } - - - WriteCommonExcept(user,"QUIT :%s",reason); - - user_hash::iterator iter = clientlist.find(user->nick); - - if (iter != clientlist.end()) - { - log(DEBUG,"deleting user hash value %d",iter->second); - clientlist.erase(iter); - } - - if (user->registered == 7) - { - purge_empty_chans(user); - } - delete user; - } -} - -void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* oldnick = strtok(params," "); - char* newnick = strtok(NULL," "); - - if ((!oldnick) || (!newnick)) - return; - - userrec* user = Find(oldnick); - - if (user) - { - if (is_uline(tcp_host)) - { - int MOD_RESULT = 0; - FOREACH_RESULT(OnUserPreNick(user,newnick)); - if (MOD_RESULT) { - // if a module returns true, the nick change couldnt be allowed - statsCollisions++; - kill_link(user,"Nickname collision"); - return; - } - if (matches_qline(newnick)) - { - statsCollisions++; - kill_link(user,"Nickname collision"); - return; - } - - // broadcast this because its a services thingy - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"n %s %s",user->nick,newnick); - NetSendToAllExcept_WithSum(tcp_host,buffer,tcp_sum); - } - WriteCommon(user,"NICK %s",newnick); - user = ReHashNick(user->nick, newnick); - if (!user) return; - if (!user->nick) return; - strlcpy(user->nick, newnick,NICKMAX); - log(DEBUG,"new nick set: %s",user->nick); - if (user->registered == 7) - { - FOREACH_MOD OnUserPostNick(user,oldnick); - } - - } -} - -// k <SOURCE> <DEST> <CHANNEL> :<REASON> -void handle_k(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* src = strtok(params," "); - char* dest = strtok(NULL," "); - char* channel = strtok(NULL," :"); - char* reason = strtok(NULL,"\r\n"); - - if ((!src) || (!dest) || (!channel) || (!reason)) - return; - - reason++; - userrec* s = Find(src); - userrec* d = Find(dest); - chanrec* c = FindChan(channel); - if ((s) && (d) && (c)) - { - kick_channel(s,d,c,reason); - return; - } - d = Find(channel); - c = FindChan(dest); - if ((s) && (d) && (c)) - { - kick_channel(s,d,c,reason); - return; - } -} - -void handle_AT(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* who = strtok(params," :"); - char* text = strtok(NULL,"\r\n"); - - if ((!who) || (!text)) - return; - - text++; - userrec* s = Find(who); - if (s) - { - WriteWallOps(s,true,text); - } -} - -void handle_H(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - log(DEBUG,"Adding ULined server %s to my map",params); - ircd_connector s; - s.SetState(STATE_DISCONNECTED); - - if (!params) - return; - - s.SetServerName(params); - - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int k = 0; k < me[j]->connectors.size(); k++) - { - if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),params)) - { - // dont allow a server to be added twice - log(DEBUG,"ULined server %s already in the map!",params); - return; - } - } - } - } - - source->connectors.push_back(s); - WriteOpers("Non-Mesh server %s has joined the network",params); -} - -void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* tm = strtok(params," "); - char* nick = strtok(NULL," "); - char* host = strtok(NULL," "); - char* dhost = strtok(NULL," "); - char* ident = strtok(NULL," "); - char* modes = strtok(NULL," "); - char* ipaddr = strtok(NULL," "); - char* server = strtok(NULL," :"); - char* gecos = strtok(NULL,"\r\n"); - - if ((!tm) || (!nick) || (!host) || (!dhost) || (!ident) || (!modes) || (!ipaddr) || (!server) || (!gecos)) - return; - - if (*gecos == ':') - gecos++; - - if (*modes == '+') - modes++; - - AddServerName(server); - - time_t TS = atoi(tm); - user_hash::iterator iter = clientlist.find(nick); - if (iter != clientlist.end()) - { - // nick collision - statsCollisions++; - WriteOpers("Nickname collision: %s@%s != %s@%s",nick,server,iter->second->nick,iter->second->server); - char str[MAXBUF]; - snprintf(str,MAXBUF,"Killed (Nick Collision (%s@%s < %s@%s))",nick,server,iter->second->nick,iter->second->server); - WriteServ(iter->second->fd, "KILL %s :%s",iter->second->nick,str); - kill_link(iter->second,str); - } - clientlist[nick] = new userrec(); - // remote users have an fd of -1. This is so that our Write abstraction - // routines know to route any messages to this record away to whatever server - // theyre on. - clientlist[nick]->fd = -1; - strlcpy(clientlist[nick]->nick, nick,NICKMAX); - strlcpy(clientlist[nick]->host, host,160); - strlcpy(clientlist[nick]->dhost, dhost,160); - clientlist[nick]->server = (char*)FindServerNamePtr(server); - strlcpy(clientlist[nick]->ident, ident,IDENTMAX+1); // +1 char to compensate for tilde - strlcpy(clientlist[nick]->fullname, gecos,MAXGECOS); - strlcpy(clientlist[nick]->ip,ipaddr,16); - strlcpy(clientlist[nick]->modes,modes,52); - clientlist[nick]->signon = TS; - clientlist[nick]->nping = 0; // this is ignored for a remote user anyway. - clientlist[nick]->lastping = 1; - clientlist[nick]->port = 0; // so is this... - clientlist[nick]->registered = 7; // this however we need to set for them to receive messages and appear online - clientlist[nick]->idle_lastmsg = TIME; // this is unrealiable and wont actually be used locally - for (int i = 0; i < MAXCHANS; i++) - { - clientlist[nick]->chans[i].channel = NULL; - clientlist[nick]->chans[i].uc_modes = 0; - } - FOREACH_MOD OnGlobalConnect(clientlist[nick]); - if (strchr(clientlist[nick]->modes,'o')) - { - FOREACH_MOD OnGlobalOper(clientlist[nick]); - } -} - -void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - if (!params) - return; - long tdiff = TIME - atoi(params); - if (tdiff) - WriteOpers("TS split for %s -> %s: %d",source->name,reply->name,tdiff); -} - -void handle_a(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* nick = strtok(params," :"); - char* gecos = strtok(NULL,"\r\n"); - - if ((!nick) || (!gecos)) - return; - - userrec* user = Find(nick); - - if (user) - strlcpy(user->fullname,gecos,MAXGECOS); -} - -void handle_b(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* nick = strtok(params," "); - char* host = strtok(NULL," "); - - if ((!nick) || (!host)) - return; - - userrec* user = Find(nick); - - if (user) - strlcpy(user->dhost,host,160); -} - -void handle_plus(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - // %s %s %d %d - // + test3.chatspike.net 7010 -2016508415 - char* servername = strtok(params," "); - char* ipaddr = strtok(NULL," "); - char* ipport = strtok(NULL," "); - char* cookie = strtok(NULL," "); - - if ((!servername) || (!ipaddr) || (!ipport) || (!cookie)) - return; - - log(DEBUG,"*** Connecting back to %s:%d",ipaddr,atoi(ipport)); - - - bool conn_already = false; - for (int i = 0; i < 32; i++) - { - if (me[i] != NULL) - { - for (unsigned int j = 0; j < me[i]->connectors.size(); j++) - { - if (!strcasecmp(me[i]->connectors[j].GetServerName().c_str(),servername)) - { - if (me[i]->connectors[j].GetServerPort() == atoi(ipport)) - { - log(DEBUG,"Already got a connection to %s:%d, ignoring +",ipaddr,atoi(ipport)); - conn_already = true; - } - } - } - } - } - if (!conn_already) - me[defaultRoute]->MeshCookie(ipaddr,atoi(ipport),atoi(cookie),servername); -} - -void handle_R(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* server = strtok(params," "); - char* data = strtok(NULL,"\r\n"); - - if ((!data) || (!server)) - { - log(DEBUG,"Someones playing silly buggers, attempting to send to a null server or send a null message (BUG?)"); - return; - } - - log(DEBUG,"Forwarded packet '%s' to '%s'",data,server); - NetSendToOne(server,data); -} - -void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* nick = strtok(params," "); - char* channel = strtok(NULL," "); - - if ((!nick) || (!channel)) - return; - - userrec* user = Find(nick); - - while (channel) - { - if ((user != NULL) && (strcmp(channel,""))) - { - char privilage = '\0'; - if (channel[0] != '#') - { - privilage = channel[0]; - channel++; - } - add_channel(user,channel,"",true); - - // now work out the privilages they should have on each channel - // and send the appropriate servermodes. - for (int i = 0; i != MAXCHANS; i++) - { - if (user->chans[i].channel) - { - if (!strcasecmp(user->chans[i].channel->name,channel)) - { - if (privilage == '@') - { - user->chans[i].uc_modes = user->chans[i].uc_modes | UCMODE_OP; - WriteChannelLocal(user->chans[i].channel, NULL, "MODE %s +o %s",channel,user->nick); - } - if (privilage == '%') - { - user->chans[i].uc_modes = user->chans[i].uc_modes | UCMODE_HOP; - WriteChannelLocal(user->chans[i].channel, NULL, "MODE %s +h %s",channel,user->nick); - } - if (privilage == '+') - { - user->chans[i].uc_modes = user->chans[i].uc_modes | UCMODE_VOICE; - WriteChannelLocal(user->chans[i].channel, NULL, "MODE %s +v %s",channel,user->nick); - } - } - } - } - - } - channel = strtok(NULL," "); - } -} - -void handle_dollar(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - log(DEBUG,"Storing routing table..."); - char* sourceserver = strtok(params," "); - char* server = strtok(NULL," "); - - if ((!sourceserver) || (!server)) - return; - - for (int i = 0; i < 32; i++) - { - if (me[i] != NULL) - { - for (unsigned int j = 0; j < me[i]->connectors.size(); j++) - { - if (!strcasecmp(me[i]->connectors[j].GetServerName().c_str(),sourceserver)) - { - me[i]->connectors[j].routes.clear(); - log(DEBUG,"Found entry for source server."); - while (server) - { - // store each route - me[i]->connectors[j].routes.push_back(server); - log(DEBUG,"*** Stored route: %s -> %s -> %s",ServerName,sourceserver,server); - server = strtok(NULL," "); - } - return; - } - } - } - } - log(DEBUG,"Warning! routing table received from nonexistent server!"); -} - -void handle_amp(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - if (!params) - return; - - log(DEBUG,"Netsplit! %s split from mesh, removing!",params); - WriteOpers("*** NOTICE - Controlled netsplit: %s split from %s",params,ServerName); - bool go_again = true; - while (go_again) - { - go_again = false; - for (int i = 0; i < 32; i++) - { - if (me[i] != NULL) - { - for (vector<ircd_connector>::iterator j = me[i]->connectors.begin(); j != me[i]->connectors.end(); j++) - { - if (!strcasecmp(j->GetServerName().c_str(),params)) - { - j->routes.clear(); - j->CloseConnection(); - me[i]->connectors.erase(j); - go_again = true; - break; - } - } - } - } - } - log(DEBUG,"Removed server. Will remove clients..."); - // iterate through the userlist and remove all users on this server. - // because we're dealing with a mesh, we dont have to deal with anything - // "down-route" from this server (nice huh) - go_again = true; - char reason[MAXBUF]; - snprintf(reason,MAXBUF,"%s %s",ServerName,params); - while (go_again) - { - go_again = false; - for (user_hash::const_iterator u = clientlist.begin(); u != clientlist.end(); u++) - { - if (!strcasecmp(u->second->server,params)) - { - kill_link(u->second,reason); - go_again = true; - break; - } - } - } - log(DEBUG,"Done with netsplit."); -} - -unsigned long authcookie; - -void handle_hash(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - // # <mask> <who-set-it> <time-set> <duration> :<reason> - log(DEBUG,"Adding G-line"); - char* mask = strtok(params," "); - char* who = strtok(NULL," "); - char* create_time = strtok(NULL," "); - char* duration = strtok(NULL," :"); - char* reason = strtok(NULL,"\r\n"); - - if ((!mask) || (!who) || (!create_time) || (!duration) || (!reason)) - return; - - reason++; - add_gline(atoi(duration),(const char*)who,(const char*)reason,(const char*)mask); - // we must update the creation time on this gline - // now that we've added it, or it wont expire at the right time. - gline_set_creation_time(mask,atoi(create_time)); - if (!atoi(duration)) - { - WriteOpers("*** %s Added permenant G-Line on %s.",who,mask); - } - else - { - WriteOpers("*** %s Added timed G-Line on %s to expire in %d seconds.",who,mask,atoi(duration)); - } - apply_lines(); -} - -void handle_dot(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - log(DEBUG,"Removing G-line"); - char* mask = strtok(params," "); - char* who = strtok(NULL," "); - - if ((!mask) || (!who)) - return; - - if (mask) - { - if (del_gline((const char*)mask)) - { - if (who) - { - WriteOpers("*** %s Removed G-line on %s.",who,mask); - } - } - } -} - -void handle_add_sqline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - // { <mask> <who-set-it> <time-set> <duration> :<reason> - log(DEBUG,"Adding Q-line"); - char* mask = strtok(params," "); - char* who = strtok(NULL," "); - char* create_time = strtok(NULL," "); - char* duration = strtok(NULL," :"); - char* reason = strtok(NULL,"\r\n"); - - if ((!mask) || (!who) || (!create_time) || (!duration) || (!reason)) - return; - - reason++; - add_qline(atoi(duration),(const char*)who,(const char*)reason,(const char*)mask); - // we must update the creation time on this gline - // now that we've added it, or it wont expire at the right time. - qline_set_creation_time(mask,atoi(create_time)); - qline_make_global(mask); - if (!atoi(duration)) - { - WriteOpers("*** %s Added permenant Q-Line on %s.",who,mask); - } - else - { - WriteOpers("*** %s Added timed Q-Line on %s to expire in %d seconds.",who,mask,atoi(duration)); - } - apply_lines(); -} - -void handle_del_sqline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - log(DEBUG,"Removing Q-line"); - char* mask = strtok(params," "); - char* who = strtok(NULL," "); - - if ((!mask) || (!who)) - return; - - if (mask) - { - if (del_qline((const char*)mask)) - { - if (who) - { - WriteOpers("*** %s Removed Q-line on %s.",who,mask); - } - } - } -} - -void handle_add_szline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - // } <mask> <who-set-it> <time-set> <duration> :<reason> - log(DEBUG,"Adding Z-line"); - char* mask = strtok(params," "); - char* who = strtok(NULL," "); - char* create_time = strtok(NULL," "); - char* duration = strtok(NULL," :"); - char* reason = strtok(NULL,"\r\n"); - - if ((!mask) || (!who) || (!create_time) || (!duration) || (!reason)) - return; - - reason++; - add_zline(atoi(duration),(const char*)who,(const char*)reason,(const char*)mask); - // we must update the creation time on this gline - // now that we've added it, or it wont expire at the right time. - zline_set_creation_time(mask,atoi(create_time)); - zline_make_global(mask); - if (!atoi(duration)) - { - WriteOpers("*** %s Added permenant Z-Line on %s.",who,mask); - } - else - { - WriteOpers("*** %s Added timed Z-Line on %s to expire in %d seconds.",who,mask,atoi(duration)); - } - apply_lines(); -} - -void handle_del_szline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - log(DEBUG,"Removing Z-line"); - char* mask = strtok(params," "); - char* who = strtok(NULL," "); - - if ((!mask) || (!who)) - return; - - if (mask) - { - if (del_zline((const char*)mask)) - { - if (who) - { - WriteOpers("*** %s Removed Q-line on %s.",who,mask); - } - } - } -} - -void handle_pipe(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) -{ - char* nick = strtok(params," "); - char* type = strtok(NULL," "); - - if ((!nick) || (!type)) - return; - - userrec* u = Find(nick); - if (u) - { - strlcpy(u->oper,type,NICKMAX); - } -} - - -void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host,char* ipaddr,int port,char* tcp_sum) -{ - char buffer[MAXBUF]; - int MOD_RESULT = 0; - - ircd_connector* cn = source->FindHost(tcp_host); - - switch(token) - { - // Y <TS> - // start netburst - case 'Y': - nb_start = TIME; - WriteOpers("Server %s is starting netburst.",tcp_host); - // now broadcast this new servers address out to all servers that are linked to us, - // except the newcomer. They'll all attempt to connect back to it. - authcookie = rand()*rand(); - snprintf(buffer,MAXBUF,"~ %lu",(unsigned long)authcookie); - NetSendToAll_WithSum(buffer,tcp_sum); - break; - // ~ - // Store authcookie - // once stored, this authcookie permits other servers to log in - // without user or password, using it. - case '~': - auth_cookies.push_back(atoi(params)); - log(DEBUG,"*** Stored auth cookie, will permit servers with auth-cookie %d",atoi(params)); - break; - // connect back to a server using an authcookie - case '+': - handle_plus(token,params,source,reply,tcp_host,tcp_sum); - break; - // routing table - case '$': - handle_dollar(token,params,source,reply,tcp_host,tcp_sum); - break; - // node unreachable - we cant route to a server, sooooo we slit it off. - // servers can generate these for themselves for an squit. - case '&': - handle_amp(token,params,source,reply,tcp_host,tcp_sum); - break; - // R <server> <data> - // redirect token, send all of <data> along to the given - // server as this server has been found to still have a route to it - case 'R': - handle_R(token,params,source,reply,tcp_host,tcp_sum); - break; - // ? - // ping - case '?': - snprintf(buffer,MAXBUF,"%s !",CreateSum().c_str()); - reply->SendPacket(buffer,tcp_host); - break; - // ? - // pong - case '!': - if (cn) - cn->ResetPing(); - break; - // * - // no operation - case '*': - break; - // no operation - reserved to prevent services issues - case ':': - break; - // N <TS> <NICK> <HOST> <DHOST> <IDENT> <MODES> <SERVER> :<GECOS> - // introduce remote client - case 'N': - handle_N(token,params,source,reply,tcp_host,tcp_sum); - break; - // a <NICK> :<GECOS> - // change GECOS (SETNAME) - case 'a': - handle_a(token,params,source,reply,tcp_host,tcp_sum); - break; - // b <NICK> :<HOST> - // change displayed host (SETHOST) - case 'b': - handle_b(token,params,source,reply,tcp_host,tcp_sum); - break; - // t <NICK> <CHANNEL> :<TOPIC> - // change a channel topic - case 't': - handle_t(token,params,source,reply,tcp_host,tcp_sum); - break; - // i <NICK> <CHANNEL> - // invite a user to a channel - case 'i': - handle_i(token,params,source,reply,tcp_host,tcp_sum); - break; - // k <SOURCE> <DEST> <CHANNEL> :<REASON> - // kick a user from a channel - case 'k': - handle_k(token,params,source,reply,tcp_host,tcp_sum); - break; - // n <NICK> <NEWNICK> - // change nickname of client -- a server should only be able to - // change the nicknames of clients that reside on it unless - // they are ulined. - case 'n': - handle_n(token,params,source,reply,tcp_host,tcp_sum); - break; - // J <NICK> <CHANLIST> - // Join user to channel list, merge channel permissions - case 'J': - handle_J(token,params,source,reply,tcp_host,tcp_sum); - break; - // T <TS> <CHANNEL> <TOPICSETTER> :<TOPIC> - // change channel topic (netburst only) - case 'T': - handle_T(token,params,source,reply,tcp_host,tcp_sum); - break; - // M <TARGET> <MODES> [MODE-PARAMETERS] - // Server setting modes on an object - case 'M': - handle_M(token,params,source,reply,tcp_host,tcp_sum); - break; - // m <SOURCE> <TARGET> <MODES> [MODE-PARAMETERS] - // User setting modes on an object - case 'm': - handle_m(token,params,source,reply,tcp_host,tcp_sum); - break; - // P <SOURCE> <TARGET> :<TEXT> - // Send a private/channel message - case 'P': - handle_P(token,params,source,reply,tcp_host,tcp_sum); - break; - // V <SOURCE> <TARGET> :<TEXT> - // Send a private/channel notice - case 'V': - handle_V(token,params,source,reply,tcp_host,tcp_sum); - break; - // v <servername> <arbitary version string> - case 'v': - handle_v(token,params,source,reply,tcp_host,tcp_sum); - break; - case '=': - handle_equals(token,params,source,reply,tcp_host,tcp_sum); - break; - // L <SOURCE> <CHANNEL> :<REASON> - // User parting a channel - case 'L': - handle_L(token,params,source,reply,tcp_host,tcp_sum); - break; - // Q <SOURCE> :<REASON> - // user quitting - case 'Q': - handle_Q(token,params,source,reply,tcp_host,tcp_sum); - break; - // H <SERVER> - // introduce non-meshable server (such as a services server) - case 'H': - handle_H(token,params,source,reply,tcp_host,tcp_sum); - break; - // K <SOURCE> <DEST> :<REASON> - // remote kill - case 'K': - handle_K(token,params,source,reply,tcp_host,tcp_sum); - break; - // @ <SOURCE> :<TEXT> - // wallops - case '@': - handle_AT(token,params,source,reply,tcp_host,tcp_sum); - break; - // # <mask> <who-set-it> <time-set> <duration> :<reason> - // add gline - case '#': - handle_hash(token,params,source,reply,tcp_host,tcp_sum); - break; - // . <mask> <who> - // remove gline - case '.': - handle_dot(token,params,source,reply,tcp_host,tcp_sum); - break; - // # <mask> <who-set-it> <time-set> <duration> :<reason> - // add gline - case '{': - handle_add_sqline(token,params,source,reply,tcp_host,tcp_sum); - break; - // . <mask> <who> - // remove gline - case '[': - handle_del_sqline(token,params,source,reply,tcp_host,tcp_sum); - break; - // # <mask> <who-set-it> <time-set> <duration> :<reason> - // add gline - case '}': - handle_add_szline(token,params,source,reply,tcp_host,tcp_sum); - break; - // . <mask> <who> - // remove gline - case ']': - handle_del_szline(token,params,source,reply,tcp_host,tcp_sum); - break; - // | <nick> <opertype> - // set opertype - case '|': - handle_pipe(token,params,source,reply,tcp_host,tcp_sum); - break; - // F <TS> - // end netburst - case 'F': - WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,TIME-nb_start); - handle_F(token,params,source,reply,tcp_host,tcp_sum); - nb_start = 0; - // tell all the other servers to use this authcookie to connect back again - // got '+ test3.chatspike.net 7010 -2016508415' from test.chatspike.net - snprintf(buffer,MAXBUF,"+ %s %s %d %lu",tcp_host,ipaddr,port,(unsigned long)authcookie); - NetSendToAllExcept_WithSum(tcp_host,buffer,tcp_sum); - break; - case '/': - WriteOpers("Server %s is IRCServices-based server (assumes-SVSMODE) - Nickname Services: %s",tcp_host,params); - strlcpy(source->nickserv,params,NICKMAX); - break; - // F <TS> - // end netburst with no mesh creation - case 'f': - WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,TIME-nb_start); - handle_F(token,params,source,reply,tcp_host,tcp_sum); - nb_start = 0; - // tell everyone else about the new server name so they just add it in the disconnected - // state - snprintf(buffer,MAXBUF,"u %s :%s",tcp_host,GetServerDescription(tcp_host).c_str()); - NetSendToAllExcept_WithSum(tcp_host,buffer,tcp_sum); - break; - // X <reserved> - // Send netburst now - case 'X': - WriteOpers("Sending my netburst to %s",tcp_host); - DoSync(source,tcp_host); - WriteOpers("Send of netburst to %s completed",tcp_host); - NetSendMyRoutingTable(); - break; - // anything else - default: - MOD_RESULT = 0; - string_list s; - char* data = strtok(params," "); - while (data) - { - if (*data == ':') - { - // the last item is a special case - data++; - char datalast[MAXBUF]; - strlcpy(datalast,data,MAXBUF); - data = strtok(NULL," "); - while (data) - { - strlcpy(datalast," ",MAXBUF); - strlcpy(datalast,data,MAXBUF); - data = strtok(NULL," "); - } - s.push_back(data); - break; - } - s.push_back(data); - data = strtok(NULL," "); - } - FOREACH_RESULT(OnMeshToken(token,s,source,reply,tcp_host,ipaddr,port)); - if (!MOD_RESULT) - WriteOpers("WARNING! Unknown datagram type '%c'",token); - break; - } -} - - -void handle_link_packet(char* tcp_msg, char* tcp_host, serverrec *serv,char* tcp_sum) -{ - if ((!strncmp(tcp_msg,"USER ",5)) || (!strncmp(tcp_msg,"NICK ",5)) || (!strncmp(tcp_msg,"PASS ",5)) || (!strncmp(tcp_msg,"SERVER ",7))) - { - // a user on a server port, just close their connection. - RemoveServer(tcp_host); - return; - } - - char response[10240]; - char token = tcp_msg[0]; - char* old = tcp_msg; - - if (!strncmp(tcp_msg,"PING",4)) - { - // some muppet of a server is sending PING. We don't know what PING is. drop it silently. - return; - } - - if ((token != ':') && (strlen(tcp_msg)>1) && (tcp_msg[1] != ' ')) - { - WriteOpers("*** Discarded %d chars illegal data from %s",strlen(tcp_msg),tcp_host); - } - - if (token == ':') // leading :servername or details - strip them off (services does this, sucky) - { - char* src = tcp_msg+1; - while (tcp_msg[0] != ' ') - tcp_msg++; - tcp_msg[0] = 0; - tcp_msg++; - char* comd = tcp_msg; - while (tcp_msg[0] != ' ') - tcp_msg++; - tcp_msg[0] = 0; - tcp_msg++; - char data[MAXBUF]; - char source[MAXBUF]; - char command[MAXBUF]; - strlcpy(data,tcp_msg,512); - strlcpy(source,src,MAXBUF); - strlcpy(command,comd,MAXBUF); - tcp_msg = old; - - // unused numeric: - // :services-dev.chatspike.net 433 Craig Craig :Nickname is registered to someone else - if (!strcmp(command,"433")) - { - token = '*'; - } - if (!strcmp(command,"432")) - { - token = '*'; - } - if (!strcmp(command,"PING")) - { - token = '*'; - } - if (!strcmp(command,"NOTICE")) - { - snprintf(tcp_msg,MAXBUF,"V %s %s",source,data); - log(DEBUG,"Rewrote NOTICE from services to: '%s'",tcp_msg); - token = tcp_msg[0]; - } - if (!strcmp(command,"QUIT")) - { - if ((!tcp_msg) || (!strcmp(data,"")) || (strcmp(data,":"))) - { - strcpy(data,":No reason"); - } - if (!strcmp(data,":")) - { - strcpy(data,":No reason"); - } - snprintf(tcp_msg,MAXBUF,"Q %s %s",source,data); - log(DEBUG,"Rewrote QUIT from services to: '%s'",tcp_msg); - token = tcp_msg[0]; - } - if (!strcmp(command,"SQUIT")) - { - snprintf(tcp_msg,MAXBUF,"& %s",source); - log(DEBUG,"Rewrote SQUIT from services to: '%s'",tcp_msg); - token = tcp_msg[0]; - } - if (!strcmp(command,"SVSMODE")) - { - snprintf(tcp_msg,MAXBUF,"m %s %s",source,data); - log(DEBUG,"Rewrote SVSMODE from services to: '%s'",tcp_msg); - token = tcp_msg[0]; - } - if (!strcmp(command,"SVS2MODE")) - { - snprintf(tcp_msg,MAXBUF,"m %s %s",source,data); - log(DEBUG,"Rewrote SVS2MODE from services to: '%s'",tcp_msg); - token = tcp_msg[0]; - } - // todo: this wont work without u:lines - // in give_ops etc allow nick on a u:lined serv to do just about anything - if (!strcmp(command,"MODE")) - { - snprintf(tcp_msg,MAXBUF,"m %s %s",source,data); - log(DEBUG,"Rewrote MODE from services to: '%s'",tcp_msg); - token = tcp_msg[0]; - } - if (!strcmp(command,"KICK")) - { - snprintf(tcp_msg,MAXBUF,"k %s %s",source,data); - log(DEBUG,"Rewrote KICK from services to: '%s'",tcp_msg); - token = tcp_msg[0]; - } - if (!strcmp(command,"KILL")) - { - snprintf(tcp_msg,MAXBUF,"K %s %s",source,data); - log(DEBUG,"Rewrote KILL from services to: '%s'",tcp_msg); - token = tcp_msg[0]; - } - if (!strcmp(command,"SVSJOIN")) - { - snprintf(tcp_msg,MAXBUF,"J %s",data); - NetSendToOne(tcp_host,tcp_msg); - char* nick = strtok(data," "); - char* chan = strtok(NULL," "); - log(DEBUG,"Rewrote SVSJOIN from services to: '%s'",tcp_msg); - userrec* u = Find(nick); - if (u) - { - add_channel(u,chan,"",true); - } - token = tcp_msg[0]; - } - - } - - char* params = tcp_msg + 2; - char finalparam[1024]; - char buffer[MAXBUF]; - strcpy(finalparam," :xxxx"); - if (strstr(tcp_msg," :")) { - strlcpy(finalparam,strstr(tcp_msg," :"),1024); - } - - - if (token == '-') { - char* cookie = strtok(params," "); - char* servername = strtok(NULL," "); - char* serverdesc = finalparam+2; - - if ((!cookie) || (!servername) || (!serverdesc)) - return; - - - WriteOpers("AuthCookie CONNECT from %s (%s)",servername,tcp_host); - - for (unsigned int u = 0; u < auth_cookies.size(); u++) - { - if (auth_cookies[u] == atoi(cookie)) - { - WriteOpers("Allowed cookie from %s, is now part of the mesh",servername); - - - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int k = 0; k < me[j]->connectors.size(); k++) - { - if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),tcp_host)) - { - me[j]->connectors[k].SetServerName(servername); - me[j]->connectors[k].SetDescription(serverdesc); - me[j]->connectors[k].SetState(STATE_CONNECTED); - AddServerName(servername); - NetSendMyRoutingTable(); - for (int t = 0; t < 32; t++) if (me[t]) for (unsigned int l = 0; l < me[t]->connectors.size(); l++) - { - if (me[t]->connectors[l].GetDescription() != "") - { - snprintf(buffer,MAXBUF,"%s = %s :%s",CreateSum().c_str(),me[t]->connectors[l].GetServerName().c_str(),me[t]->connectors[l].GetDescription().c_str()); - serv->SendPacket(buffer,servername); - } - } - snprintf(buffer,MAXBUF,"%s v %s %s",CreateSum().c_str(),ServerName,GetVersionString().c_str()); - serv->SendPacket(buffer,tcp_host); - return; - } - } - } - WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right now! Possible intrusion attempt!",tcp_host); - return; - } - - - return; - } - } - // bad cookie, bad bad! go sit in the corner! - WriteOpers("Bad cookie from %s!",servername); - return; - } - else - if (token == 'S') { - // S test.chatspike.net password portn :ChatSpike InspIRCd test server - char* servername = strtok(params," "); - char* password = strtok(NULL," "); - char* myport = strtok(NULL," "); - char* revision = strtok(NULL," "); - char* serverdesc = finalparam+2; - - if ((!servername) || (!password) || (!myport) || (!revision) || (!serverdesc)) - return; - - WriteOpers("CONNECT from %s (%s) (their port: %d)",servername,tcp_host,atoi(myport)); - - ircd_connector* cn = serv->FindHost(servername); - - if (cn) - { - WriteOpers("CONNECT aborted: Server %s already exists from %s",servername,ServerName); - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"E :Server %s already exists!",servername); - serv->SendPacket(buffer,tcp_host); - serv->FlushWriteBuffers(); - RemoveServer(tcp_host); - return; - } - - if (std::string(revision) != GetRevision()) - { - WriteOpers("CONNECT aborted: Could not link to %s, is an incompatible version %s, our version is %s",servername,revision,GetRevision().c_str()); - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"E :Version number mismatch"); - serv->SendPacket(buffer,tcp_host); - serv->FlushWriteBuffers(); - RemoveServer(tcp_host); - RemoveServer(servername); - return; - } - - for (unsigned int j = 0; j < serv->connectors.size(); j++) - { - if (!strcasecmp(serv->connectors[j].GetServerName().c_str(),tcp_host)) - { - serv->connectors[j].SetServerName(servername); - serv->connectors[j].SetDescription(serverdesc); - serv->connectors[j].SetServerPort(atoi(myport)); - } - } - - char Link_ServerName[1024]; - char Link_IPAddr[1024]; - char Link_Port[1024]; - char Link_Pass[1024]; - char Link_SendPass[1024]; - int LinkPort = 0; - - // search for a corresponding <link> block in the config files - for (int i = 0; i < ConfValueEnum("link",&config_f); i++) - { - ConfValue("link","name",i,Link_ServerName,&config_f); - ConfValue("link","ipaddr",i,Link_IPAddr,&config_f); - ConfValue("link","port",i,Link_Port,&config_f); - ConfValue("link","recvpass",i,Link_Pass,&config_f); - ConfValue("link","sendpass",i,Link_SendPass,&config_f); - log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass); - LinkPort = atoi(Link_Port); - if ((!strcasecmp(Link_ServerName,servername)) && (!strcmp(Link_Pass,password))) - { - // we have a matching link line - - // send a 'diminutive' server message back... - snprintf(response,10240,"%s s %s %s :%s",CreateSum().c_str(),ServerName,Link_SendPass,ServerDesc); - serv->SendPacket(response,servername); - - for (unsigned int t = 0; t < serv->connectors.size(); t++) - { - if (!strcasecmp(serv->connectors[t].GetServerName().c_str(),servername)) - { - serv->connectors[t].SetState(STATE_CONNECTED); - AddServerName(servername); - } - } - - return; - } - } - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"E :Access is denied (no matching link block)"); - serv->SendPacket(buffer,tcp_host); - serv->FlushWriteBuffers(); - WriteOpers("CONNECT from %s denied, no matching link block",servername); - RemoveServer(tcp_host); - RemoveServer(servername); - return; - } - else - if (token == 's') { - // S test.chatspike.net password :ChatSpike InspIRCd test server - char* servername = strtok(params," "); - char* password = strtok(NULL," "); - char* serverdesc = finalparam+2; - - if ((!servername) || (!password) || (!serverdesc)) - return; - - // TODO: we should do a check here to ensure that this server is one we recently initiated a - // link with, and didnt hear an 's' or 'E' back from yet (these are the only two valid responses - // to an 'S' command. If we didn't recently send an 'S' to this server, theyre trying to spoof - // a connect, so put out an oper alert! - - // for now, just accept all, we'll fix that later. - WriteOpers("%s accepted our link credentials ",servername); - - char Link_ServerName[1024]; - char Link_IPAddr[1024]; - char Link_Port[1024]; - char Link_Pass[1024]; - char Link_SendPass[1024]; - int LinkPort = 0; - - // search for a corresponding <link> block in the config files - for (int i = 0; i < ConfValueEnum("link",&config_f); i++) - { - ConfValue("link","name",i,Link_ServerName,&config_f); - ConfValue("link","ipaddr",i,Link_IPAddr,&config_f); - ConfValue("link","port",i,Link_Port,&config_f); - ConfValue("link","recvpass",i,Link_Pass,&config_f); - ConfValue("link","sendpass",i,Link_SendPass,&config_f); - log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass); - LinkPort = atoi(Link_Port); - if (!strcasecmp(Link_ServerName,servername)) - { - // matching link at this end too, we're all done! - // at this point we must begin key exchange and insert this - // server into our 'active' table. - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int k = 0; k < me[j]->connectors.size(); k++) - { - if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),tcp_host)) - { - char buffer[MAXBUF]; - me[j]->connectors[k].SetDescription(serverdesc); - me[j]->connectors[k].SetState(STATE_CONNECTED); - AddServerName(servername); - snprintf(buffer,MAXBUF,"%s X 0",CreateSum().c_str()); - serv->SendPacket(buffer,tcp_host); - DoSync(me[j],tcp_host); - NetSendMyRoutingTable(); - return; - } - } - } - } - } - else { - log(DEBUG,"Server names '%s' and '%s' don't match",Link_ServerName,servername); - } - } - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"E :Access is denied (no matching link block)"); - serv->SendPacket(buffer,tcp_host); - serv->FlushWriteBuffers(); - WriteOpers("CONNECT from %s denied, no matching link block",servername); - RemoveServer(tcp_host); - RemoveServer(servername); - return; - } - else - if (token == 'U') { - // U services.chatspike.net password :ChatSpike Services - // - // non-meshed link, used by services. Everything coming from a non-meshed link is auto broadcasted. - char* servername = strtok(params," "); - char* password = strtok(NULL," "); - char* serverdesc = finalparam+2; - - if ((!password) || (!servername) || (!serverdesc)) - return; - - char Link_ServerName[1024]; - char Link_IPAddr[1024]; - char Link_Port[1024]; - char Link_Pass[1024]; - char Link_SendPass[1024]; - int LinkPort = 0; - - log(DEBUG,"U-token linked server detected.\n\nservername='%s' password='%s'\n\n",servername,password); - - - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int k = 0; k < me[j]->connectors.size(); k++) - { - if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),servername)) - { - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"E :Access is denied (Server exists in the mesh)"); - serv->SendPacket(buffer,tcp_host); - serv->FlushWriteBuffers(); - WriteOpers("CONNECT from %s denied, \"%s\" already exists!",tcp_host,servername); - RemoveServer(tcp_host); - return; - } - } - } - } - - // search for a corresponding <link> block in the config files - for (int i = 0; i < ConfValueEnum("link",&config_f); i++) - { - ConfValue("link","name",i,Link_ServerName,&config_f); - ConfValue("link","ipaddr",i,Link_IPAddr,&config_f); - ConfValue("link","port",i,Link_Port,&config_f); - ConfValue("link","recvpass",i,Link_Pass,&config_f); - ConfValue("link","sendpass",i,Link_SendPass,&config_f); - log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass); - LinkPort = atoi(Link_Port); - if ((!strcasecmp(Link_ServerName,servername)) && (!strcmp(Link_Pass,password))) - { - // matching link at this end too, we're all done! - // at this point we must begin key exchange and insert this - // server into our 'active' table. - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int k = 0; k < me[j]->connectors.size(); k++) - { - if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),tcp_host)) - { - char buffer[MAXBUF]; - log(DEBUG,"Found matching link block"); - me[j]->connectors[k].SetDescription(serverdesc); - me[j]->connectors[k].SetServerName(servername); - me[j]->connectors[k].SetState(STATE_SERVICES); - AddServerName(servername); - snprintf(buffer,MAXBUF,"%s X 0",CreateSum().c_str()); - serv->SendPacket(buffer,servername); - snprintf(buffer,MAXBUF,"%s s %s %s %d :%s",CreateSum().c_str(),ServerName,Link_SendPass,LinkPort,ServerDesc); - serv->SendPacket(buffer,servername); - DoSync(me[j],servername); - snprintf(buffer,MAXBUF,"H %s",servername); - NetSendToAllExcept(servername,buffer); - WriteOpers("Non-Mesh server %s has joined the network",servername); - log(DEBUG,"******** SENDING MY ROUTING TABLE! *******"); - NetSendMyRoutingTable(); - return; - } - } - } - } - } - else { - log(DEBUG,"Server names '%s' and '%s' don't match",Link_ServerName,servername); - } - } - log(DEBUG,"No matching link block found"); - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"E :Access is denied (no matching link block)"); - serv->SendPacket(buffer,tcp_host); - serv->FlushWriteBuffers(); - WriteOpers("CONNECT from %s denied, no matching link block",servername); - RemoveServer(tcp_host); - RemoveServer(servername); - return; - } - else - if (token == 'E') { - char* error_message = finalparam+2; - - if (!error_message) - return; - - WriteOpers("ERROR from %s: %s",tcp_host,error_message); - return; - } - else { - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int x = 0; x < me[j]->connectors.size(); x++) - { - log(DEBUG,"Servers are: '%s' '%s'",tcp_host,me[j]->connectors[x].GetServerName().c_str()); - if (!strcasecmp(me[j]->connectors[x].GetServerName().c_str(),tcp_host)) - { - if ((me[j]->connectors[x].GetState() == STATE_CONNECTED) || (me[j]->connectors[x].GetState() == STATE_SERVICES) || (me[j]->connectors[x].GetState() == STATE_COOKIE_OUTBOUND)) - { - // found a valid ircd_connector. - if ((params) && (*params)) - process_restricted_commands(token,params,me[j],serv,tcp_host,me[j]->connectors[x].GetServerIP(),me[j]->connectors[x].GetServerPort(),tcp_sum); - return; - } - } - } - } - } - - log(DEBUG,"Unrecognised token or unauthenticated host in datagram from %s: %c",tcp_host,token); - } -} - long duration(const char* str) { char n_field[MAXBUF]; |