diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-14 18:29:44 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-14 18:29:44 +0000 |
commit | 36127608a981c809c9b8e52980a6c23874eb633e (patch) | |
tree | 65f21267165128c6b4f7acf3e443c0f163bd9f35 | |
parent | ce82525b3e7daf417448390479de7fd7da7d27ec (diff) |
Added 'uniqueness sums': http://www.inspircd.org/wiki/InspIRCd_Server_Protocol#Uniqueness_Sums
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1378 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/commands.h | 48 | ||||
-rw-r--r-- | include/connection.h | 4 | ||||
-rw-r--r-- | include/inspircd.h | 2 | ||||
-rw-r--r-- | src/commands.cpp | 151 | ||||
-rw-r--r-- | src/connection.cpp | 62 | ||||
-rw-r--r-- | src/inspircd.cpp | 96 | ||||
-rw-r--r-- | src/xline.cpp | 6 |
7 files changed, 240 insertions, 129 deletions
diff --git a/include/commands.h b/include/commands.h index 2777de1a2..f83ab5f81 100644 --- a/include/commands.h +++ b/include/commands.h @@ -84,33 +84,33 @@ void handle_unloadmodule(char **parameters, int pcnt, userrec *user); /** Special functions for processing server to server traffic */ -void handle_link_packet(char* tcp_msg, char* tcp_host, serverrec *serv); -void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host,char* ipaddr,int port); +void handle_link_packet(char* tcp_msg, char* tcp_host, serverrec *serv, char* tcp_sum); +void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host,char* ipaddr,int port, char* tcp_sum); /** These are the handlers for server commands (tokens) */ -void handle_amp(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_dollar(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_R(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_plus(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_b(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_a(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_AT(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_k(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_K(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_m(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_M(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); -void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host); +void handle_amp(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_dollar(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_R(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_plus(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_b(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_a(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_AT(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_k(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_K(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_m(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_M(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); +void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum); /** Functions for u:lined servers */ diff --git a/include/connection.h b/include/connection.h index c6adedf26..b84d39df9 100644 --- a/include/connection.h +++ b/include/connection.h @@ -39,6 +39,8 @@ #define STATE_NOAUTH_OUTBOUND 4 #define STATE_SERVICES 5 +std::string CreateSum(); + /** Each connection has one or more of these * each represents ONE outbound connection to another ircd * so each inbound has multiple outbounds. A listening socket @@ -302,7 +304,7 @@ class connection : public Extensible * If no data is available this function returns false. * This function will automatically close broken links and reroute pathways, generating split messages on the network. */ - bool RecvPacket(std::deque<std::string> &messages, char* host); + bool RecvPacket(std::deque<std::string> &messages, char* host, std::deque<std::string> &sums); /** Find the ircd_connector oject related to a certain servername given in 'host' */ diff --git a/include/inspircd.h b/include/inspircd.h index d58d4eeff..4a6e98437 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -168,9 +168,11 @@ void NoticeAllOpers(userrec *source, bool local_only, char* text, ...); void NetSendToCommon(userrec* u, char* s); void NetSendToAll(char* s); +void NetSendToAll_WithSum(char* s,char* u); void NetSendToAllAlive(char* s); void NetSendToOne(char* target,char* s); void NetSendToAllExcept(const char* target,char* s); +void NetSendToAllExcept_WithSum(const char* target,char* s,char* u); void NetSendMyRoutingTable(); bool ChanAnyOnThisServer(chanrec *c,char* servername); bool CommonOnThisServer(userrec* u,const char* servername); diff --git a/src/commands.cpp b/src/commands.cpp index 18329e9b3..692dcd223 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1918,7 +1918,7 @@ void handle_nick(char **parameters, int pcnt, userrec *user) } -void handle_v(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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"); @@ -1942,7 +1942,7 @@ void handle_v(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," :"); @@ -1986,7 +1986,7 @@ void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* } -void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," :"); @@ -2018,7 +2018,7 @@ void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* } -void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2037,7 +2037,7 @@ void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," :"); @@ -2059,7 +2059,7 @@ void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* } -void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2084,7 +2084,7 @@ void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_M(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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]; @@ -2119,7 +2119,7 @@ void handle_M(char token,char* params,serverrec* source,serverrec* reply, char* // 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) +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]; @@ -2162,7 +2162,7 @@ void handle_m(char token,char* params,serverrec* source,serverrec* reply, char* } -void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) { char* nick = NULL; char* channel = NULL; @@ -2200,7 +2200,7 @@ void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_K(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," :"); @@ -2222,7 +2222,7 @@ void handle_K(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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"); @@ -2259,7 +2259,7 @@ void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2291,7 +2291,7 @@ void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* // broadcast this because its a services thingy char buffer[MAXBUF]; snprintf(buffer,MAXBUF,"n %s %s",user->nick,newnick); - NetSendToAllExcept(tcp_host,buffer); + NetSendToAllExcept_WithSum(tcp_host,buffer,tcp_sum); } WriteCommon(user,"NICK %s",newnick); user = ReHashNick(user->nick, newnick); @@ -2303,7 +2303,7 @@ void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* } // k <SOURCE> <DEST> <CHANNEL> :<REASON> -void handle_k(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2331,7 +2331,7 @@ void handle_k(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_AT(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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"); @@ -2347,7 +2347,7 @@ void handle_AT(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_H(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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; @@ -2378,7 +2378,7 @@ void handle_H(char token,char* params,serverrec* source,serverrec* reply, char* WriteOpers("Non-Mesh server %s has joined the network",params); } -void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2441,7 +2441,7 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) { if (!params) return; @@ -2450,7 +2450,7 @@ void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* 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) +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"); @@ -2464,7 +2464,7 @@ void handle_a(char token,char* params,serverrec* source,serverrec* reply, char* strlcpy(user->fullname,gecos,MAXBUF); } -void handle_b(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2478,7 +2478,7 @@ void handle_b(char token,char* params,serverrec* source,serverrec* reply, char* strlcpy(user->dhost,host,160); } -void handle_plus(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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 @@ -2515,7 +2515,7 @@ void handle_plus(char token,char* params,serverrec* source,serverrec* reply, cha me[defaultRoute]->MeshCookie(ipaddr,atoi(ipport),atoi(cookie),servername); } -void handle_R(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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"); @@ -2530,11 +2530,8 @@ void handle_R(char token,char* params,serverrec* source,serverrec* reply, char* NetSendToOne(server,data); } -void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) { - // IMPORTANT NOTE - // The J token currently has no timestamp - this needs looking at - // because it will allow splitriding. char* nick = strtok(params," "); char* channel = strtok(NULL," "); @@ -2587,7 +2584,7 @@ void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* } } -void handle_dollar(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2621,7 +2618,7 @@ void handle_dollar(char token,char* params,serverrec* source,serverrec* reply, c log(DEBUG,"Warning! routing table received from nonexistent server!"); } -void handle_amp(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +void handle_amp(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) { if (!params) return; @@ -2674,7 +2671,7 @@ void handle_amp(char token,char* params,serverrec* source,serverrec* reply, char unsigned long authcookie; -void handle_hash(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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"); @@ -2703,7 +2700,7 @@ void handle_hash(char token,char* params,serverrec* source,serverrec* reply, cha apply_lines(); } -void handle_dot(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2724,7 +2721,7 @@ void handle_dot(char token,char* params,serverrec* source,serverrec* reply, char } } -void handle_add_sqline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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"); @@ -2754,7 +2751,7 @@ void handle_add_sqline(char token,char* params,serverrec* source,serverrec* repl apply_lines(); } -void handle_del_sqline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2775,7 +2772,7 @@ void handle_del_sqline(char token,char* params,serverrec* source,serverrec* repl } } -void handle_add_szline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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"); @@ -2805,7 +2802,7 @@ void handle_add_szline(char token,char* params,serverrec* source,serverrec* repl apply_lines(); } -void handle_del_szline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +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," "); @@ -2826,7 +2823,7 @@ void handle_del_szline(char token,char* params,serverrec* source,serverrec* repl } } -void handle_pipe(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) +void handle_pipe(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host, char* tcp_sum) { char* nick = strtok(params," "); char* type = strtok(params," "); @@ -2842,7 +2839,7 @@ void handle_pipe(char token,char* params,serverrec* source,serverrec* reply, cha } -void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host,char* ipaddr,int port) +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; @@ -2858,7 +2855,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve // except the newcomer. They'll all attempt to connect back to it. authcookie = rand()*rand(); snprintf(buffer,MAXBUF,"~ %lu",(unsigned long)authcookie); - NetSendToAll(buffer); + NetSendToAll_WithSum(buffer,tcp_sum); break; // ~ // Store authcookie @@ -2870,22 +2867,22 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve break; // connect back to a server using an authcookie case '+': - handle_plus(token,params,source,reply,tcp_host); + handle_plus(token,params,source,reply,tcp_host,tcp_sum); break; // routing table case '$': - handle_dollar(token,params,source,reply,tcp_host); + 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); + 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); + handle_R(token,params,source,reply,tcp_host,tcp_sum); break; // ? // ping @@ -2906,144 +2903,144 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve // N <TS> <NICK> <HOST> <DHOST> <IDENT> <MODES> <SERVER> :<GECOS> // introduce remote client case 'N': - handle_N(token,params,source,reply,tcp_host); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + handle_v(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); + 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); + 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); + 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); + handle_K(token,params,source,reply,tcp_host,tcp_sum); break; // @ <SOURCE> :<TEXT> // wallops case '@': - handle_AT(token,params,source,reply,tcp_host); + 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); + handle_hash(token,params,source,reply,tcp_host,tcp_sum); break; // . <mask> <who> // remove gline case '.': - handle_dot(token,params,source,reply,tcp_host); + 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); + 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); + 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); + 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); + 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); + 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); + 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(tcp_host,buffer); + NetSendToAllExcept_WithSum(tcp_host,buffer,tcp_sum); break; case '/': WriteOpers("Server %s is IRCServices-based server (assumes-SVSMODE) - Nickname Services: %s",tcp_host,params); @@ -3053,12 +3050,12 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve // 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); + 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(tcp_host,buffer); + NetSendToAllExcept_WithSum(tcp_host,buffer,tcp_sum); break; // X <reserved> // Send netburst now @@ -3102,7 +3099,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve } -void handle_link_packet(char* tcp_msg, char* tcp_host, serverrec *serv) +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))) { @@ -3358,7 +3355,7 @@ void handle_link_packet(char* tcp_msg, char* tcp_host, serverrec *serv) { // we have a matching link line - // send a 'diminutive' server message back... - snprintf(response,10240,"s %s %s :%s",ServerName,Link_SendPass,ServerDesc); + snprintf(response,10240,"%s s %s %s :%s",CreateSum().c_str(),ServerName,Link_SendPass,ServerDesc); serv->SendPacket(response,servername); for (int t = 0; t < serv->connectors.size(); t++) @@ -3431,7 +3428,7 @@ void handle_link_packet(char* tcp_msg, char* tcp_host, serverrec *serv) char buffer[MAXBUF]; me[j]->connectors[k].SetDescription(serverdesc); me[j]->connectors[k].SetState(STATE_CONNECTED); - snprintf(buffer,MAXBUF,"X 0"); + snprintf(buffer,MAXBUF,"%s X 0",CreateSum().c_str()); serv->SendPacket(buffer,tcp_host); DoSync(me[j],tcp_host); NetSendMyRoutingTable(); @@ -3522,9 +3519,9 @@ void handle_link_packet(char* tcp_msg, char* tcp_host, serverrec *serv) me[j]->connectors[k].SetDescription(serverdesc); me[j]->connectors[k].SetServerName(servername); me[j]->connectors[k].SetState(STATE_SERVICES); - snprintf(buffer,MAXBUF,"X 0"); + snprintf(buffer,MAXBUF,"%s X 0",CreateSum().c_str()); serv->SendPacket(buffer,servername); - snprintf(buffer,MAXBUF,"s %s %s %lu :%s",ServerName,Link_SendPass,LinkPort,ServerDesc); + snprintf(buffer,MAXBUF,"%s s %s %s %lu :%s",CreateSum().c_str(),ServerName,Link_SendPass,LinkPort,ServerDesc); serv->SendPacket(buffer,servername); DoSync(me[j],servername); snprintf(buffer,MAXBUF,"H %s",servername); @@ -3575,7 +3572,7 @@ void handle_link_packet(char* tcp_msg, char* tcp_host, serverrec *serv) { // 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()); + process_restricted_commands(token,params,me[j],serv,tcp_host,me[j]->connectors[x].GetServerIP(),me[j]->connectors[x].GetServerPort(),tcp_sum); return; } } diff --git a/src/connection.cpp b/src/connection.cpp index d42dea179..031feba02 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -35,6 +35,8 @@ using namespace std; extern std::vector<Module*> modules; extern std::vector<ircd_module*> factory; +std::deque<std::string> xsums; + extern int MODCOUNT; extern time_t TIME; @@ -56,6 +58,19 @@ extern time_t TIME; * to it, to maintain the mesh link. */ +char* xsumtable = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +// creates a random id for a line for detection of duplicate messages +std::string CreateSum() +{ + char sum[9]; + sum[0] = ':'; + sum[8] = '\0'; + for(int q = 1; q < 8; q++) + sum[q] = xsumtable[rand()%52]; + return sum; +} + connection::connection() { fd = 0; @@ -487,10 +502,27 @@ bool connection::SendPacket(char *message, const char* sendhost) } } +bool already_have_sum(std::string sum) +{ + for (int i = 0; i < xsums.size(); i++) + { + if (xsums[i] == sum) + { + return true; + } + } + if (xsums.size() >= 128) + { + xsums.pop_front(); + } + xsums.push_back(sum); + return false; +} + // receives a packet from any where there is data waiting, first come, first served // fills the message and host values with the host where the data came from. -bool connection::RecvPacket(std::deque<std::string> &messages, char* recvhost) +bool connection::RecvPacket(std::deque<std::string> &messages, char* recvhost,std::deque<std::string> &sums) { char data[65536]; memset(data, 0, 65536); @@ -532,9 +564,35 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* recvhost) std::string text = this->connectors[i].GetBuffer(); if (text != "") { + if ((text[0] == ':') && (text.find(" ") != std::string::npos)) + { + std::string orig = text; + log(DEBUG,"Original: %s",text.c_str()); + std::string sum = text.substr(1,text.find(" ")-1); + text = text.substr(text.find(" ")+1,text.length()); + std::string possible_token = text.substr(1,text.find(" ")-1); + if (possible_token.length() > 1) + { + sums.push_back("*"); + text = orig; + log(DEBUG,"Non-mesh, non-tokenized string passed up the chain"); + } + else + { + log(DEBUG,"Packet sum: '%s'",sum.c_str()); + if ((already_have_sum(sum)) && (sum != "*")) + { + // we don't accept dupes + log(DEBUG,"Duplicate packet sum %s from server %s dropped",sum.c_str(),this->connectors[i].GetServerName().c_str()); + continue; + } + sums.push_back(sum.c_str()); + } + } + else sums.push_back("*"); messages.push_back(text.c_str()); strlcpy(recvhost,this->connectors[i].GetServerName().c_str(),160); - log(DEBUG,"main: Connection::RecvPacket() %d:%s->%s",pushed++,recvhost,text.c_str()); + log(DEBUG,"Connection::RecvPacket() %d:%s->%s",pushed++,recvhost,text.c_str()); } } return true; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 1b7e55272..d5778e804 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -1059,8 +1059,8 @@ bool CommonOnThisServer(userrec* u,const char* servername) void NetSendToCommon(userrec* u, char* s) { char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"%s",s); - + snprintf(buffer,MAXBUF,"%s %s",CreateSum().c_str(),s); + log(DEBUG,"NetSendToCommon: '%s' '%s'",u->nick,s); std::string msg = buffer; @@ -1086,7 +1086,7 @@ void NetSendToCommon(userrec* u, char* s) void NetSendToAll(char* s) { char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"%s",s); + snprintf(buffer,MAXBUF,"%s %s",CreateSum().c_str(),s); log(DEBUG,"NetSendToAll: '%s'",s); @@ -1106,10 +1106,33 @@ void NetSendToAll(char* s) } } +void NetSendToAll_WithSum(char* s,char* u) +{ + char buffer[MAXBUF]; + snprintf(buffer,MAXBUF,":%s %s",u,s); + + log(DEBUG,"NetSendToAll: '%s'",s); + + std::string msg = buffer; + FOREACH_MOD OnPacketTransmit(msg,s); + strlcpy(buffer,msg.c_str(),MAXBUF); + + for (int j = 0; j < 32; j++) + { + if (me[j] != NULL) + { + for (int k = 0; k < me[j]->connectors.size(); k++) + { + me[j]->SendPacket(buffer,me[j]->connectors[k].GetServerName().c_str()); + } + } + } +} + void NetSendToAllAlive(char* s) { char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"%s",s); + snprintf(buffer,MAXBUF,"%s %s",CreateSum().c_str(),s); log(DEBUG,"NetSendToAllAlive: '%s'",s); @@ -1140,7 +1163,7 @@ void NetSendToAllAlive(char* s) void NetSendToOne(char* target,char* s) { char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"%s",s); + snprintf(buffer,MAXBUF,"%s %s",CreateSum().c_str(),s); log(DEBUG,"NetSendToOne: '%s' '%s'",target,s); @@ -1166,7 +1189,7 @@ void NetSendToOne(char* target,char* s) void NetSendToAllExcept(const char* target,char* s) { char buffer[MAXBUF]; - snprintf(buffer,MAXBUF,"%s",s); + snprintf(buffer,MAXBUF,"%s %s",CreateSum().c_str(),s); log(DEBUG,"NetSendToAllExcept: '%s' '%s'",target,s); @@ -1189,6 +1212,32 @@ void NetSendToAllExcept(const char* target,char* s) } } +void NetSendToAllExcept_WithSum(const char* target,char* s,char* u) +{ + char buffer[MAXBUF]; + snprintf(buffer,MAXBUF,":%s %s",u,s); + + log(DEBUG,"NetSendToAllExcept: '%s' '%s'",target,s); + + std::string msg = buffer; + FOREACH_MOD OnPacketTransmit(msg,s); + strlcpy(buffer,msg.c_str(),MAXBUF); + + for (int j = 0; j < 32; j++) + { + if (me[j] != NULL) + { + for (int k = 0; k < me[j]->connectors.size(); k++) + { + if (strcasecmp(me[j]->connectors[k].GetServerName().c_str(),target)) + { + me[j]->SendPacket(buffer,me[j]->connectors[k].GetServerName().c_str()); + } + } + } + } +} + void WriteMode(const char* modes, int flags, const char* text, ...) { @@ -3583,7 +3632,7 @@ void DoSync(serverrec* serv, char* tcp_host) // send start of sync marker: Y <timestamp> // at this point the ircd receiving it starts broadcasting this netburst to all ircds // except the ones its receiving it from. - snprintf(data,MAXBUF,"Y %lu",(unsigned long)TIME); + snprintf(data,MAXBUF,"%s Y %lu",CreateSum().c_str(),(unsigned long)TIME); serv->SendPacket(data,tcp_host); // send users and channels @@ -3598,7 +3647,7 @@ void DoSync(serverrec* serv, char* tcp_host) { if (is_uline(me[j]->connectors[k].GetServerName().c_str())) { - snprintf(data,MAXBUF,"H %s",me[j]->connectors[k].GetServerName().c_str()); + snprintf(data,MAXBUF,"%s H %s",CreateSum().c_str(),me[j]->connectors[k].GetServerName().c_str()); serv->SendPacket(data,tcp_host); } } @@ -3606,17 +3655,17 @@ void DoSync(serverrec* serv, char* tcp_host) } // send our version for the remote side to cache - snprintf(data,MAXBUF,"v %s %s",ServerName,GetVersionString().c_str()); + snprintf(data,MAXBUF,"%s v %s %s",CreateSum().c_str(),ServerName,GetVersionString().c_str()); serv->SendPacket(data,tcp_host); // sync the users and channels, give the modules a look-in. for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++) { - snprintf(data,MAXBUF,"N %lu %s %s %s %s +%s %s %s :%s",(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->ip,u->second->server,u->second->fullname); + snprintf(data,MAXBUF,"%s N %lu %s %s %s %s +%s %s %s :%s",CreateSum().c_str(),(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->ip,u->second->server,u->second->fullname); serv->SendPacket(data,tcp_host); if (strchr(u->second->modes,'o')) { - snprintf(data,MAXBUF,"| %s %s",u->second->nick,u->second->oper); + snprintf(data,MAXBUF,"%s | %s %s",CreateSum().c_str(),u->second->nick,u->second->oper); serv->SendPacket(data,tcp_host); } for (int i = 0; i <= MODCOUNT; i++) @@ -3624,14 +3673,14 @@ void DoSync(serverrec* serv, char* tcp_host) string_list l = modules[i]->OnUserSync(u->second); for (int j = 0; j < l.size(); j++) { - strlcpy(data,l[j].c_str(),MAXBUF); + snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str()); serv->SendPacket(data,tcp_host); } } char* chl = chlist(u->second,u->second); if (strcmp(chl,"")) { - snprintf(data,MAXBUF,"J %s %s",u->second->nick,chl); + snprintf(data,MAXBUF,"%s J %s %s",CreateSum().c_str(),u->second->nick,chl); serv->SendPacket(data,tcp_host); } } @@ -3645,27 +3694,27 @@ void DoSync(serverrec* serv, char* tcp_host) string_list l = modules[i]->OnChannelSync(c->second); for (int j = 0; j < l.size(); j++) { - strlcpy(data,l[j].c_str(),MAXBUF); + snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str()); serv->SendPacket(data,tcp_host); } } if (c->second->topic[0]) { - snprintf(data,MAXBUF,"T %lu %s %s :%s",(unsigned long)c->second->topicset,c->second->setby,c->second->name,c->second->topic); + snprintf(data,MAXBUF,"%s T %lu %s %s :%s",CreateSum().c_str(),(unsigned long)c->second->topicset,c->second->setby,c->second->name,c->second->topic); serv->SendPacket(data,tcp_host); } // send current banlist for (BanList::iterator b = c->second->bans.begin(); b != c->second->bans.end(); b++) { - snprintf(data,MAXBUF,"M %s +b %s",c->second->name,b->data); + snprintf(data,MAXBUF,"%s M %s +b %s",CreateSum().c_str(),c->second->name,b->data); serv->SendPacket(data,tcp_host); } } // sync global zlines, glines, etc sync_xlines(serv,tcp_host); - snprintf(data,MAXBUF,"F %lu",(unsigned long)TIME); + snprintf(data,MAXBUF,"%s F %lu",CreateSum().c_str(),(unsigned long)TIME); serv->SendPacket(data,tcp_host); log(DEBUG,"Sent sync"); // ircd sends its serverlist after the end of sync here @@ -4184,7 +4233,7 @@ int InspIRCd(char** argv, int argc) WritePID(PID); length = sizeof (client); - char tcp_msg[MAXBUF],tcp_host[MAXBUF]; + char tcp_msg[MAXBUF],tcp_host[MAXBUF],tcp_sum[MAXBUF]; #ifdef USE_KQUEUE struct kevent ke; @@ -4287,12 +4336,15 @@ int InspIRCd(char** argv, int argc) for (int x = 0; x < SERVERportCount; x++) { std::deque<std::string> msgs; + std::deque<std::string> sums; msgs.clear(); - if ((me[x]) && (me[x]->RecvPacket(msgs, tcp_host))) + sums.clear(); + if ((me[x]) && (me[x]->RecvPacket(msgs, tcp_host, sums))) { for (int ctr = 0; ctr < msgs.size(); ctr++) { strlcpy(tcp_msg,msgs[ctr].c_str(),MAXBUF); + strlcpy(tcp_sum,msgs[ctr].c_str(),MAXBUF); log(DEBUG,"Processing: %s",tcp_msg); if (!tcp_msg[0]) { @@ -4306,16 +4358,16 @@ int InspIRCd(char** argv, int argc) { if ((tcp_msg[0] != 'Y') && (tcp_msg[0] != 'X') && (tcp_msg[0] != 'F')) { - NetSendToAllExcept(tcp_host,tcp_msg); + NetSendToAllExcept_WithSum(tcp_host,tcp_msg,tcp_sum); } } else - NetSendToAllExcept(tcp_host,tcp_msg); + NetSendToAllExcept_WithSum(tcp_host,tcp_msg,tcp_sum); } std::string msg = tcp_msg; FOREACH_MOD OnPacketReceive(msg,tcp_host); strlcpy(tcp_msg,msg.c_str(),MAXBUF); - handle_link_packet(tcp_msg, tcp_host, me[x]); + handle_link_packet(tcp_msg, tcp_host, me[x], tcp_sum); } goto label; } diff --git a/src/xline.cpp b/src/xline.cpp index 8f69455df..a7a5d0f30 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -399,7 +399,7 @@ void sync_xlines(serverrec* serv, char* tcp_host) { if (i->is_global) { - snprintf(data,MAXBUF,"} %s %s %lu %lu :%s",i->ipaddr,i->source,(unsigned long)i->set_time,(unsigned long)i->duration,i->reason); + snprintf(data,MAXBUF,"%s } %s %s %lu %lu :%s",CreateSum().c_str(),i->ipaddr,i->source,(unsigned long)i->set_time,(unsigned long)i->duration,i->reason); serv->SendPacket(data,tcp_host); } } @@ -407,14 +407,14 @@ void sync_xlines(serverrec* serv, char* tcp_host) { if (i->is_global) { - snprintf(data,MAXBUF,"{ %s %s %lu %lu :%s",i->nick,i->source,(unsigned long)i->set_time,(unsigned long)i->duration,i->reason); + snprintf(data,MAXBUF,"%s { %s %s %lu %lu :%s",CreateSum().c_str(),i->nick,i->source,(unsigned long)i->set_time,(unsigned long)i->duration,i->reason); serv->SendPacket(data,tcp_host); } } // glines are always global, so no need to check for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++) { - snprintf(data,MAXBUF,"# %s %s %lu %lu :%s",i->hostmask,i->source,(unsigned long)i->set_time,(unsigned long)i->duration,i->reason); + snprintf(data,MAXBUF,"%s # %s %s %lu %lu :%s",CreateSum().c_str(),i->hostmask,i->source,(unsigned long)i->set_time,(unsigned long)i->duration,i->reason); serv->SendPacket(data,tcp_host); } } |