X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcommands.cpp;h=bd30e5573417bc1414fc79a81a6558943b061daf;hb=c0fd2894d2de4c3fd0c9e160860f24f290bb52d9;hp=85eb833c29beddd5bff1584c92de1a73b406aac7;hpb=0340f1a432d684347d8dbc3aa85c8436c56d4039;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/commands.cpp b/src/commands.cpp index 85eb833c2..bd30e5573 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -50,6 +50,8 @@ #include "message.h" #include "mode.h" #include "xline.h" +#include "inspstring.h" +#include "dnsqueue.h" #ifdef GCC3 #define nspace __gnu_cxx @@ -60,8 +62,8 @@ using namespace std; extern int MODCOUNT; -extern vector modules; -extern vector factory; +extern std::vector modules; +extern std::vector factory; extern int LogLevel; extern char ServerName[MAXBUF]; @@ -89,7 +91,8 @@ extern time_t nb_start; extern bool nofork; -extern std::vector fd_reap; +extern time_t TIME; + extern std::vector module_names; extern char MyExecutable[1024]; @@ -116,28 +119,35 @@ const long duration_y = duration_w * 52; namespace nspace { - template<> struct nspace::hash - { - size_t operator()(const struct in_addr &a) const - { - size_t q; - memcpy(&q,&a,sizeof(size_t)); - return q; - } - }; - - template<> struct nspace::hash - { - size_t operator()(const string &s) const - { - char a[MAXBUF]; - static struct hash strhash; - strlcpy(a,s.c_str(),MAXBUF); - strlower(a); - return strhash(a); - } - }; -} +#ifdef GCC34 + template<> struct hash +#else + template<> struct nspace::hash +#endif + { + size_t operator()(const struct in_addr &a) const + { + size_t q; + memcpy(&q,&a,sizeof(size_t)); + return q; + } + }; +#ifdef GCC34 + template<> struct hash +#else + template<> struct nspace::hash +#endif + { + size_t operator()(const string &s) const + { + char a[MAXBUF]; + static struct hash strhash; + strlcpy(a,s.c_str(),MAXBUF); + strlower(a); + return strhash(a); + } + }; +} struct StrHashComp @@ -148,6 +158,8 @@ struct StrHashComp char a[MAXBUF],b[MAXBUF]; strlcpy(a,s1.c_str(),MAXBUF); strlcpy(b,s2.c_str(),MAXBUF); + strlower(a); + strlower(b); return (strcasecmp(a,b) == 0); } @@ -188,7 +200,6 @@ extern address_cache IP; void handle_join(char **parameters, int pcnt, userrec *user) { chanrec* Ptr; - int i = 0; if (loop_call(handle_join,parameters,pcnt,user,0,0,1)) return; @@ -201,8 +212,6 @@ void handle_join(char **parameters, int pcnt, userrec *user) void handle_part(char **parameters, int pcnt, userrec *user) { - chanrec* Ptr; - if (pcnt > 1) { if (loop_call(handle_part,parameters,pcnt,user,0,pcnt-2,0)) @@ -224,7 +233,7 @@ void handle_kick(char **parameters, int pcnt, userrec *user) if ((!u) || (!Ptr)) { - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); return; } @@ -253,12 +262,36 @@ void handle_kick(char **parameters, int pcnt, userrec *user) } // this must be propogated so that channel membership is kept in step network-wide - char buffer[MAXBUF]; snprintf(buffer,MAXBUF,"k %s %s %s :%s",user->nick,u->nick,Ptr->name,reason); NetSendToAll(buffer); } +void handle_loadmodule(char **parameters, int pcnt, userrec *user) +{ + if (LoadModule(parameters[0])) + { + WriteOpers("*** NEW MODULE: %s",parameters[0]); + WriteServ(user->fd,"975 %s %s :Module successfully loaded.",user->nick, parameters[0]); + } + else + { + WriteServ(user->fd,"974 %s %s :Failed to load module: %s",user->nick, parameters[0],ModuleError()); + } +} + +void handle_unloadmodule(char **parameters, int pcnt, userrec *user) +{ + if (UnloadModule(parameters[0])) + { + WriteOpers("*** MODULE UNLOADED: %s",parameters[0]); + WriteServ(user->fd,"973 %s %s :Module successfully unloaded.",user->nick, parameters[0]); + } + else + { + WriteServ(user->fd,"972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ModuleError()); + } +} void handle_die(char **parameters, int pcnt, userrec *user) { @@ -277,7 +310,6 @@ void handle_die(char **parameters, int pcnt, userrec *user) void handle_restart(char **parameters, int pcnt, userrec *user) { - char restart[1024]; char *argv[32]; log(DEFAULT,"Restart: %s",user->nick); if (!strcmp(parameters[0],restartpass)) @@ -301,16 +333,16 @@ void handle_restart(char **parameters, int pcnt, userrec *user) sleep(1); for (int i = 0; i < 65536; i++) { - int on = 0; + int on = 1; struct linger linger = { 0 }; setsockopt(i, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)); linger.l_onoff = 1; - linger.l_linger = 0; + linger.l_linger = 1; setsockopt(i, SOL_SOCKET, SO_LINGER, (const char*)&linger,sizeof(linger)); Blocking(i); close(i); } - sleep(5); + sleep(2); execv(MyExecutable,argv); @@ -326,10 +358,18 @@ void handle_kill(char **parameters, int pcnt, userrec *user) { userrec *u = Find(parameters[0]); char killreason[MAXBUF]; - + log(DEBUG,"kill: %s %s",parameters[0],parameters[1]); if (u) { + log(DEBUG,"into kill mechanism"); + int MOD_RESULT = 0; + FOREACH_RESULT(OnKill(user,u,parameters[1])); + if (MOD_RESULT) { + log(DEBUG,"A module prevented the kill with result %d",MOD_RESULT); + return; + } + if (strcmp(ServerName,u->server)) { // remote kill @@ -345,16 +385,18 @@ void handle_kill(char **parameters, int pcnt, userrec *user) if (iter != clientlist.end()) { log(DEBUG,"deleting user hash value %d",iter->second); - if ((iter->second) && (user->registered == 7)) { - delete iter->second; - } - clientlist.erase(iter); + clientlist.erase(iter); } - purge_empty_chans(); + if (u->registered == 7) + { + purge_empty_chans(u); + } + delete u; } else { // local kill + log(DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick, ServerName,user->dhost,user->nick,parameters[1]); WriteTo(user, u, "KILL %s :%s!%s!%s (%s)", u->nick, ServerName,user->dhost,user->nick,parameters[1]); WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)",user->nick,u->nick,u->ident,u->host,parameters[1]); snprintf(killreason,MAXBUF,"Killed (%s (%s))",user->nick,parameters[1]); @@ -363,7 +405,7 @@ void handle_kill(char **parameters, int pcnt, userrec *user) } else { - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } @@ -385,6 +427,7 @@ void handle_pass(char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"462 %s :You may not reregister",user->nick); return; } + strlcpy(user->password,parameters[0],MAXBUF); if (!strcasecmp(parameters[0],Passwd(user))) { user->haspassed = true; @@ -459,6 +502,11 @@ void handle_topic(char **parameters, int pcnt, userrec *user) Ptr = FindChan(parameters[0]); if (Ptr) { + if (((Ptr) && (!has_channel(user,Ptr))) && (Ptr->secret)) + { + WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name); + return; + } if (Ptr->topicset) { WriteServ(user->fd,"332 %s %s :%s", user->nick, Ptr->name, Ptr->topic); @@ -471,7 +519,7 @@ void handle_topic(char **parameters, int pcnt, userrec *user) } else { - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } return; @@ -483,22 +531,35 @@ void handle_topic(char **parameters, int pcnt, userrec *user) Ptr = FindChan(parameters[0]); if (Ptr) { + if ((Ptr) && (!has_channel(user,Ptr))) + { + WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name); + return; + } if ((Ptr->topiclock) && (cstatus(user,Ptr)fd,"482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name); return; } - + char topic[MAXBUF]; strlcpy(topic,parameters[1],MAXBUF); if (strlen(topic)>MAXTOPIC) { topic[MAXTOPIC-1] = '\0'; } - + + if (!strcasecmp(user->server,ServerName)) + { + int MOD_RESULT = 0; + FOREACH_RESULT(OnLocalTopicChange(user,Ptr,topic)); + if (MOD_RESULT) + return; + } + strlcpy(Ptr->topic,topic,MAXBUF); strlcpy(Ptr->setby,user->nick,NICKMAX); - Ptr->topicset = time(NULL); + Ptr->topicset = TIME; WriteChannel(Ptr,user,"TOPIC %s :%s",Ptr->name, Ptr->topic); // t token must go to ALL servers!!! @@ -508,7 +569,7 @@ void handle_topic(char **parameters, int pcnt, userrec *user) } else { - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } } @@ -518,18 +579,28 @@ void handle_names(char **parameters, int pcnt, userrec *user) { chanrec* c; + if (!pcnt) + { + WriteServ(user->fd,"366 %s * :End of /NAMES list.",user->nick); + return; + } + if (loop_call(handle_names,parameters,pcnt,user,0,pcnt-1,0)) return; c = FindChan(parameters[0]); if (c) { - /*WriteServ(user->fd,"353 %s = %s :%s", user->nick, c->name,*/ + if (((c) && (!has_channel(user,c))) && (c->secret)) + { + WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, c->name); + return; + } userlist(user,c); WriteServ(user->fd,"366 %s %s :End of /NAMES list.", user->nick, c->name); } else { - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } @@ -538,7 +609,7 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user) userrec *dest; chanrec *chan; - user->idle_lastmsg = time(NULL); + user->idle_lastmsg = TIME; if (loop_call(handle_privmsg,parameters,pcnt,user,0,pcnt-2,0)) return; @@ -577,7 +648,7 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user) else { /* no such nick/channel */ - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } return; } @@ -617,7 +688,7 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user) else { /* no such nick/channel */ - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } @@ -626,7 +697,7 @@ void handle_notice(char **parameters, int pcnt, userrec *user) userrec *dest; chanrec *chan; - user->idle_lastmsg = time(NULL); + user->idle_lastmsg = TIME; if (loop_call(handle_notice,parameters,pcnt,user,0,pcnt-2,0)) return; @@ -665,7 +736,7 @@ void handle_notice(char **parameters, int pcnt, userrec *user) else { /* no such nick/channel */ - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } return; } @@ -697,7 +768,7 @@ void handle_notice(char **parameters, int pcnt, userrec *user) else { /* no such nick/channel */ - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } @@ -709,9 +780,39 @@ void handle_server(char **parameters, int pcnt, userrec *user) void handle_info(char **parameters, int pcnt, userrec *user) { - WriteServ(user->fd,"371 %s :The Inspire IRCd Project Has been brought to you by the following people..",user->nick); - WriteServ(user->fd,"371 %s :Craig Edwards, Craig McLure, and Others..",user->nick); - WriteServ(user->fd,"371 %s :Will finish this later when i can be arsed :p",user->nick); + WriteServ(user->fd,"371 %s :. o O (The Inspire Internet Relay Chat Server) O o .",user->nick); + WriteServ(user->fd,"371 %s : ",user->nick); + WriteServ(user->fd,"371 %s :Core developers: Craig Edwards (Brain)",user->nick); + WriteServ(user->fd,"371 %s : Craig McLure",user->nick); + WriteServ(user->fd,"371 %s : ",user->nick); + WriteServ(user->fd,"371 %s :Contributors: typobox43",user->nick); + WriteServ(user->fd,"371 %s : w00t",user->nick); + WriteServ(user->fd,"371 %s : Om",user->nick); + WriteServ(user->fd,"371 %s : Jazza",user->nick); + WriteServ(user->fd,"371 %s : ",user->nick); + WriteServ(user->fd,"371 %s :Testers: CC",user->nick); + WriteServ(user->fd,"371 %s : Piggles",user->nick); + WriteServ(user->fd,"371 %s : Foamy",user->nick); + WriteServ(user->fd,"371 %s : Hart",user->nick); + WriteServ(user->fd,"371 %s : RageD",user->nick); + WriteServ(user->fd,"371 %s : [ed]",user->nick); + WriteServ(user->fd,"371 %s : Azhrarn",user->nick); + WriteServ(user->fd,"371 %s : nenolod",user->nick); + WriteServ(user->fd,"371 %s : luigiman",user->nick); + WriteServ(user->fd,"371 %s : Chu",user->nick); + WriteServ(user->fd,"371 %s : aquanight",user->nick); + WriteServ(user->fd,"371 %s : xptek",user->nick); + WriteServ(user->fd,"371 %s : Grantlinks",user->nick); + WriteServ(user->fd,"371 %s : Rob",user->nick); + WriteServ(user->fd,"371 %s : angelic",user->nick); + WriteServ(user->fd,"371 %s : Jason",user->nick); + WriteServ(user->fd,"371 %s : ",user->nick); + WriteServ(user->fd,"371 %s :Thanks to irc-junkie and searchirc",user->nick); + WriteServ(user->fd,"371 %s :for the nice comments and the help",user->nick); + WriteServ(user->fd,"371 %s :you gave us in attracting users to",user->nick); + WriteServ(user->fd,"371 %s :this software.",user->nick); + WriteServ(user->fd,"371 %s : ",user->nick); + WriteServ(user->fd,"371 %s :Best experienced with: An IRC client.",user->nick); FOREACH_MOD OnInfo(user); WriteServ(user->fd,"374 %s :End of /INFO list",user->nick); } @@ -730,7 +831,6 @@ void handle_time(char **parameters, int pcnt, userrec *user) void handle_whois(char **parameters, int pcnt, userrec *user) { userrec *dest; - char *t; if (loop_call(handle_whois,parameters,pcnt,user,0,pcnt-1,0)) return; @@ -754,7 +854,7 @@ void handle_whois(char **parameters, int pcnt, userrec *user) { WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg); } - if (strchr(dest->modes,'o')) + if ((strchr(dest->modes,'o')) && (strcmp(dest->oper,""))) { WriteServ(user->fd,"313 %s %s :is %s %s on %s",user->nick, dest->nick, (strchr("aeiou",dest->oper[0]) ? "an" : "a"),dest->oper, Network); @@ -763,20 +863,20 @@ void handle_whois(char **parameters, int pcnt, userrec *user) if (!strcasecmp(user->server,dest->server)) { // idle time and signon line can only be sent if youre on the same server (according to RFC) - WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-time(NULL)), dest->signon); + WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-TIME), dest->signon); } WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick); } else { - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } else { /* no such nick/channel */ - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } @@ -801,8 +901,8 @@ void handle_quit(char **parameters, int pcnt, userrec *user) reason[MAXQUIT-1] = '\0'; } - Write(user->fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,parameters[0]); - WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,parameters[0]); + Write(user->fd,"ERROR :Closing link (%s@%s) [%s%s]",user->ident,user->host,PrefixQuit,parameters[0]); + WriteOpers("*** Client exiting: %s!%s@%s [%s%s]",user->nick,user->ident,user->host,PrefixQuit,parameters[0]); WriteCommonExcept(user,"QUIT :%s%s",PrefixQuit,parameters[0]); char buffer[MAXBUF]; @@ -823,21 +923,24 @@ void handle_quit(char **parameters, int pcnt, userrec *user) AddWhoWas(user); } + FOREACH_MOD OnUserDisconnect(user); + /* push the socket on a stack of sockets due to be closed at the next opportunity */ - fd_reap.push_back(user->fd); + if (user->fd > -1) + { + shutdown(user->fd,2); + close(user->fd); + } if (iter != clientlist.end()) { clientlist.erase(iter); - log(DEBUG,"deleting user hash value %d",iter->second); - //if ((user) && (user->registered == 7)) { - //delete user; - //} } if (user->registered == 7) { - purge_empty_chans(); + purge_empty_chans(user); } + delete user; } void handle_who(char **parameters, int pcnt, userrec *user) @@ -876,11 +979,11 @@ void handle_who(char **parameters, int pcnt, userrec *user) } if (Ptr) { - WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, Ptr->name); + WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]); } else { - WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, user->nick); + WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]); } return; } @@ -905,11 +1008,11 @@ void handle_who(char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname); } } - WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, Ptr->name); + WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]); } else { - WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]); + WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } else @@ -953,7 +1056,7 @@ void handle_who(char **parameters, int pcnt, userrec *user) } } } - WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, user->nick); + WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]); return; } } @@ -966,8 +1069,6 @@ void handle_wallops(char **parameters, int pcnt, userrec *user) void handle_list(char **parameters, int pcnt, userrec *user) { - chanrec* Ptr; - WriteServ(user->fd,"321 %s Channel :Users Name",user->nick); for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++) { @@ -1036,7 +1137,6 @@ void handle_user(char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"461 %s USER :Not enough parameters",user->nick); } else { - WriteServ(user->fd,"NOTICE Auth :No ident response, ident prefixed with ~"); strcpy(user->ident,"~"); /* we arent checking ident... but these days why bother anyway? */ strlcat(user->ident,parameters[0],IDENTMAX); strlcpy(user->fullname,parameters[3],128); @@ -1052,6 +1152,7 @@ void handle_user(char **parameters, int pcnt, userrec *user) if (user->registered == 3) { /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */ + FOREACH_MOD OnUserRegister(user); ConnectUser(user); } } @@ -1167,10 +1268,29 @@ void handle_modules(char **parameters, int pcnt, userrec *user) { for (int i = 0; i < module_names.size(); i++) { - Version V = modules[i]->GetVersion(); - char modulename[MAXBUF]; - strlcpy(modulename,module_names[i].c_str(),256); - WriteServ(user->fd,"900 %s :0x%08lx %d.%d.%d.%d %s",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,CleanFilename(modulename)); + Version V = modules[i]->GetVersion(); + char modulename[MAXBUF]; + char flagstate[MAXBUF]; + strcpy(flagstate,""); + if (V.Flags & VF_STATIC) + strlcat(flagstate,", static",MAXBUF); + if (V.Flags & VF_VENDOR) + strlcat(flagstate,", vendor",MAXBUF); + if (V.Flags & VF_COMMON) + strlcat(flagstate,", common",MAXBUF); + if (V.Flags & VF_SERVICEPROVIDER) + strlcat(flagstate,", service provider",MAXBUF); + if (!flagstate[0]) + strcpy(flagstate," "); + strlcpy(modulename,module_names[i].c_str(),256); + if (strchr(user->modes,'o')) + { + WriteServ(user->fd,"900 %s :0x%08lx %d.%d.%d.%d %s (%s)",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,CleanFilename(modulename),flagstate+2); + } + else + { + WriteServ(user->fd,"900 %s :%s",user->nick,CleanFilename(modulename)); + } } } @@ -1188,7 +1308,9 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } - if (!strcasecmp(parameters[0],"c")) + FOREACH_MOD OnStats(*parameters[0]); + + if (*parameters[0] == 'c') { for (int i = 0; i < ConfValueEnum("link",&config_f); i++) { @@ -1200,7 +1322,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } } - if (!strcasecmp(parameters[0],"i")) + if (*parameters[0] == 'i') { int idx = 0; for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++) @@ -1210,7 +1332,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } } - if (!strcasecmp(parameters[0],"y")) + if (*parameters[0] == 'y') { int idx = 0; for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++) @@ -1220,7 +1342,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } } - if (!strcmp(parameters[0],"U")) + if (*parameters[0] == 'U') { for (int i = 0; i < ConfValueEnum("uline",&config_f); i++) { @@ -1229,14 +1351,14 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } } - if (!strcmp(parameters[0],"P")) + if (*parameters[0] == 'P') { int idx = 0; for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++) { if (strchr(i->second->modes,'o')) { - WriteServ(user->fd,"249 %s :%s (%s@%s) Idle: %d",user->nick,i->second->nick,i->second->ident,i->second->dhost,(time(NULL) - i->second->idle_lastmsg)); + WriteServ(user->fd,"249 %s :%s (%s@%s) Idle: %d",user->nick,i->second->nick,i->second->ident,i->second->dhost,(TIME - i->second->idle_lastmsg)); idx++; } } @@ -1244,28 +1366,33 @@ void handle_stats(char **parameters, int pcnt, userrec *user) //249 [Brain] :bwoadway-monitor (~wgmon@204.152.186.58) Idle: 18 } - if (!strcmp(parameters[0],"k")) + if (*parameters[0] == 'k') { stats_k(user); } - if (!strcmp(parameters[0],"g")) + if (*parameters[0] == 'g') { stats_g(user); } - if (!strcmp(parameters[0],"q")) + if (*parameters[0] == 'q') { stats_q(user); } - if (!strcmp(parameters[0],"Z")) + if (*parameters[0] == 'Z') { stats_z(user); } + if (*parameters[0] == 'e') + { + stats_e(user); + } + /* stats m (list number of times each command has been used, plus bytecount) */ - if (!strcmp(parameters[0],"m")) + if (*parameters[0] == 'm') { for (int i = 0; i < cmdlist.size(); i++) { @@ -1282,7 +1409,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } /* stats z (debug and memory info) */ - if (!strcmp(parameters[0],"z")) + if (*parameters[0] == 'z') { WriteServ(user->fd,"249 %s :Users(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,clientlist.size(),clientlist.size()*sizeof(userrec),clientlist.bucket_count()); WriteServ(user->fd,"249 %s :Channels(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,chanlist.size(),chanlist.size()*sizeof(chanrec),chanlist.bucket_count()); @@ -1295,7 +1422,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } /* stats o */ - if (!strcmp(parameters[0],"o")) + if (*parameters[0] == 'o') { for (int i = 0; i < ConfValueEnum("oper",&config_f); i++) { @@ -1310,7 +1437,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } /* stats l (show user I/O stats) */ - if (!strcmp(parameters[0],"l")) + if (*parameters[0] == 'l') { WriteServ(user->fd,"211 %s :server:port nick bytes_in cmds_in bytes_out cmds_out",user->nick); for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++) @@ -1328,10 +1455,10 @@ void handle_stats(char **parameters, int pcnt, userrec *user) } /* stats u (show server uptime) */ - if (!strcmp(parameters[0],"u")) + if (*parameters[0] == 'u') { time_t current_time = 0; - current_time = time(NULL); + current_time = TIME; time_t server_uptime = current_time - startup_time; struct tm* stime; stime = gmtime(&server_uptime); @@ -1360,7 +1487,7 @@ void handle_connect(char **parameters, int pcnt, userrec *user) char Link_Pass[1024]; int LinkPort; bool found = false; - + for (int i = 0; i < ConfValueEnum("link",&config_f); i++) { if (!found) @@ -1411,7 +1538,40 @@ void handle_squit(char **parameters, int pcnt, userrec *user) } else { - WriteServ(user->fd,"NOTICE :*** Remote SQUIT not supported yet."); + 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 = false; + for (int j = 0; j < 32; j++) + { + if (me[j] != NULL) + { + for (int x = 0; x < me[j]->connectors.size(); x++) + { + if (!strcasecmp(me[j]->connectors[x].GetServerName().c_str(),parameters[0])) + { + // found a valid ircd_connector. + have_this_server = true; + break; + } + } + } + } + if (have_this_server) + { + WriteOpers("SQUIT command issued by %s to remove %s from the mesh",user->nick,parameters[0]); + WriteServ(user->fd,"NOTICE %s :*** Removing remote server %s.",user->nick,parameters[0]); + char buffer[MAXBUF]; + snprintf(buffer,MAXBUF,"& %s",parameters[0]); + NetSendToAll(buffer); + DoSplit(parameters[0]); + } + else + { + WriteServ(user->fd,"NOTICE %s :*** No such server exists in the mesh.",user->nick); + } } } @@ -1437,7 +1597,7 @@ void handle_map(char **parameters, int pcnt, userrec *user) 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)usercnt())*100)); + 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) @@ -1447,7 +1607,7 @@ void handle_map(char **parameters, int pcnt, userrec *user) snprintf(line,MAXBUF,"006 %s :%c-%s",user->nick,islast(me[j]->connectors[k].GetServerName().c_str()),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)usercnt())*100)); + 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)); } } } @@ -1457,8 +1617,6 @@ void handle_map(char **parameters, int pcnt, userrec *user) bool is_uline(const char* server) { char ServName[MAXBUF]; - int i,j; - for (int i = 0; i < ConfValueEnum("uline",&config_f); i++) { ConfValue("uline","server",i,ServName,&config_f); @@ -1469,7 +1627,18 @@ bool is_uline(const char* server) } return false; } - +int operstrcmp(char* data,char* input) +{ + int MOD_RESULT = 0; + FOREACH_RESULT(OnOperCompare(data,input)) + log(DEBUG,"operstrcmp: %d",MOD_RESULT); + if (MOD_RESULT == 1) + return 0; + if (MOD_RESULT == -1) + return 1; + log(DEBUG,"strcmp fallback: '%s' '%s' %d",data,input,strcmp(data,input)); + return strcmp(data,input); +} void handle_oper(char **parameters, int pcnt, userrec *user) { @@ -1477,47 +1646,77 @@ void handle_oper(char **parameters, int pcnt, userrec *user) char Password[MAXBUF]; char OperType[MAXBUF]; char TypeName[MAXBUF]; - char Hostname[MAXBUF]; - int i,j; + char HostName[MAXBUF]; + char TheHost[MAXBUF]; + int j; + bool found = false; + bool fail2 = false; + char global[MAXBUF]; + + snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host); for (int i = 0; i < ConfValueEnum("oper",&config_f); i++) { ConfValue("oper","name",i,LoginName,&config_f); ConfValue("oper","password",i,Password,&config_f); - if ((!strcmp(LoginName,parameters[0])) && (!strcmp(Password,parameters[1]))) + ConfValue("oper","type",i,OperType,&config_f); + ConfValue("oper","host",i,HostName,&config_f); + if ((!strcmp(LoginName,parameters[0])) && (!operstrcmp(Password,parameters[1])) && (match(TheHost,HostName))) { - /* correct oper credentials */ - ConfValue("oper","type",i,OperType,&config_f); - WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType); - WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType); - WriteServ(user->fd,"MODE %s :+o",user->nick); - char global[MAXBUF]; - snprintf(global,MAXBUF,"M %s +o",user->nick); - NetSendToAll(global); + fail2 = true; for (j =0; j < ConfValueEnum("type",&config_f); j++) { ConfValue("type","name",j,TypeName,&config_f); + if (!strcmp(TypeName,OperType)) { /* found this oper's opertype */ snprintf(global,MAXBUF,"| %s %s",user->nick,TypeName); NetSendToAll(global); - ConfValue("type","host",j,Hostname,&config_f); - ChangeDisplayedHost(user,Hostname); + ConfValue("type","host",j,HostName,&config_f); + ChangeDisplayedHost(user,HostName); strlcpy(user->oper,TypeName,NICKMAX); + found = true; + fail2 = false; + break; } } - if (!strchr(user->modes,'o')) - { - strcat(user->modes,"o"); - } + } + if (found) + break; + } + if (found) + { + /* correct oper credentials */ + WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType); + WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType); + if (!strchr(user->modes,'o')) + { + strcat(user->modes,"o"); + WriteServ(user->fd,"MODE %s :+o",user->nick); + snprintf(global,MAXBUF,"M %s +o",user->nick); + NetSendToAll(global); FOREACH_MOD OnOper(user); - return; + log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType); + AddOper(user); + } + } + else + { + if (!fail2) + { + WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick); + WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host); + log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host); + } + else + { + WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick); + WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType); + log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host); } } - /* no such oper */ - WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick); - WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host); + return; } void handle_nick(char **parameters, int pcnt, userrec *user) @@ -1532,7 +1731,7 @@ void handle_nick(char **parameters, int pcnt, userrec *user) log(DEBUG,"invalid parameter passed to handle_nick"); return; } - if (!strlen(parameters[0])) + if (!parameters[0][0]) { log(DEBUG,"zero length new nick passed to handle_nick"); return; @@ -1590,13 +1789,15 @@ void handle_nick(char **parameters, int pcnt, userrec *user) WriteCommon(user,"NICK %s",parameters[0]); - // Q token must go to ALL servers!!! + // N token must go to ALL servers!!! char buffer[MAXBUF]; snprintf(buffer,MAXBUF,"n %s %s",user->nick,parameters[0]); NetSendToAll(buffer); - } + char oldnick[NICKMAX]; + strlcpy(oldnick,user->nick,NICKMAX); + /* change the nick of the user in the users_hash */ user = ReHashNick(user->nick, parameters[0]); /* actually change the nick within the record */ @@ -1608,12 +1809,24 @@ void handle_nick(char **parameters, int pcnt, userrec *user) log(DEBUG,"new nick set: %s",user->nick); if (user->registered < 3) + { user->registered = (user->registered | 2); + // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change + // and unless we're lucky we'll get a duff one later on. + user->dns_done = (!lookup_dns(user->nick)); + if (user->dns_done) + log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick); + } if (user->registered == 3) { /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */ + FOREACH_MOD OnUserRegister(user); ConnectUser(user); } + if (user->registered == 7) + { + FOREACH_MOD OnUserPostNick(user,oldnick); + } } @@ -1703,7 +1916,7 @@ void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* WriteChannelLocal(c,u,"TOPIC %s :%s",c->name,topic); strlcpy(c->topic,topic,MAXTOPIC); strlcpy(c->setby,u->nick,NICKMAX); - c->topicset = time(NULL); + c->topicset = TIME; } } @@ -1794,14 +2007,28 @@ 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) { - char* nick = strtok(params," "); - char* channel = strtok(NULL," :"); - char* reason = strtok(NULL,"\r\n"); + 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"); + channel++; + reason = ""; + } + else + { + nick = strtok(params," "); + channel = strtok(NULL," :"); + reason = strtok(NULL,"\r\n"); + reason++; + } userrec* user = Find(nick); - reason++; - if (user) + if ((user) && (channel) && (reason)) { - if (strcmp(reason,"")) + if ((!reason) && (*reason != '\0')) { del_channel(user,channel,reason,true); } @@ -1855,13 +2082,14 @@ void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* if (iter != clientlist.end()) { log(DEBUG,"deleting user hash value %d",iter->second); - if ((iter->second) && (user->registered == 7)) { - delete iter->second; - } clientlist.erase(iter); } - purge_empty_chans(); + if (user->registered == 7) + { + purge_empty_chans(user); + } + delete user; } } @@ -1871,10 +2099,9 @@ void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* char* newnick = strtok(NULL," "); userrec* user = Find(oldnick); - + if (user) { - WriteCommon(user,"NICK %s",newnick); if (is_uline(tcp_host)) { int MOD_RESULT = 0; @@ -1893,8 +2120,9 @@ 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); - NetSendToAll(buffer); + NetSendToAllExcept(tcp_host,buffer); } + WriteCommon(user,"NICK %s",newnick); user = ReHashNick(user->nick, newnick); if (!user) return; if (!user->nick) return; @@ -2002,22 +2230,28 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* strlcpy(clientlist[nick]->server, server,256); strlcpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for tilde strlcpy(clientlist[nick]->fullname, gecos,128); + strlcpy(clientlist[nick]->ip,ipaddr,32); 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(NULL); // this is unrealiable and wont actually be used locally + 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; - } + 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) { - long tdiff = time(NULL) - atoi(params); + long tdiff = TIME - atoi(params); if (tdiff) WriteOpers("TS split for %s -> %s: %d",source->name,reply->name,tdiff); } @@ -2221,7 +2455,7 @@ void handle_amp(char token,char* params,serverrec* source,serverrec* reply, char } } -long authcookie; +unsigned long authcookie; void handle_hash(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host) { @@ -2232,7 +2466,8 @@ void handle_hash(char token,char* params,serverrec* source,serverrec* reply, cha char* create_time = strtok(NULL," "); char* duration = strtok(NULL," :"); char* reason = strtok(NULL,"\r\n"); - add_gline(atoi(duration),who,reason,mask); + 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)); @@ -2254,7 +2489,7 @@ void handle_dot(char token,char* params,serverrec* source,serverrec* reply, char char* who = strtok(NULL," "); if (mask) { - if (del_gline(mask)) + if (del_gline((const char*)mask)) { if (who) { @@ -2273,7 +2508,8 @@ void handle_add_sqline(char token,char* params,serverrec* source,serverrec* repl char* create_time = strtok(NULL," "); char* duration = strtok(NULL," :"); char* reason = strtok(NULL,"\r\n"); - add_qline(atoi(duration),who,reason,mask); + 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)); @@ -2296,7 +2532,7 @@ void handle_del_sqline(char token,char* params,serverrec* source,serverrec* repl char* who = strtok(NULL," "); if (mask) { - if (del_qline(mask)) + if (del_qline((const char*)mask)) { if (who) { @@ -2315,7 +2551,8 @@ void handle_add_szline(char token,char* params,serverrec* source,serverrec* repl char* create_time = strtok(NULL," "); char* duration = strtok(NULL," :"); char* reason = strtok(NULL,"\r\n"); - add_zline(atoi(duration),who,reason,mask); + 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)); @@ -2338,7 +2575,7 @@ void handle_del_szline(char token,char* params,serverrec* source,serverrec* repl char* who = strtok(NULL," "); if (mask) { - if (del_zline(mask)) + if (del_zline((const char*)mask)) { if (who) { @@ -2363,18 +2600,19 @@ 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) { char buffer[MAXBUF]; + int MOD_RESULT = 0; switch(token) { // Y // start netburst case 'Y': - nb_start = time(NULL); + 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,"~ %d",authcookie); + snprintf(buffer,MAXBUF,"~ %lu",(unsigned long)authcookie); NetSendToAll(buffer); break; // ~ @@ -2547,12 +2785,12 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve // F // end netburst case 'F': - WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,time(NULL)-nb_start); + WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,TIME-nb_start); handle_F(token,params,source,reply,tcp_host); 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 %d",tcp_host,ipaddr,port,authcookie); + snprintf(buffer,MAXBUF,"+ %s %s %d %lu",tcp_host,ipaddr,port,(unsigned long)authcookie); NetSendToAllExcept(tcp_host,buffer); break; case '/': @@ -2562,7 +2800,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve // F // end netburst with no mesh creation case 'f': - WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,time(NULL)-nb_start); + WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,TIME-nb_start); handle_F(token,params,source,reply,tcp_host); nb_start = 0; // tell everyone else about the new server name so they just add it in the disconnected @@ -2580,7 +2818,33 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve break; // anything else default: - WriteOpers("WARNING! Unknown datagram type '%c'",token); + 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; } } @@ -2588,7 +2852,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) { - if ((!strncmp(udp_msg,"USER ",5)) || (!strncmp(udp_msg,"NICK ",5))) + if ((!strncmp(udp_msg,"USER ",5)) || (!strncmp(udp_msg,"NICK ",5)) || (!strncmp(udp_msg,"PASS ",5)) || (!strncmp(udp_msg,"SERVER ",7))) { // a user on a server port, just close their connection. RemoveServer(tcp_host); @@ -2599,6 +2863,11 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) char token = udp_msg[0]; char* old = udp_msg; + if ((token != ':') && (strlen(udp_msg)>1) && (udp_msg[1] != ' ')) + { + WriteOpers("*** Discarded %d chars illegal data from %s",strlen(udp_msg),tcp_host); + } + if (token == ':') // leading :servername or details - strip them off (services does this, sucky) { char* src = udp_msg+1; @@ -2629,6 +2898,10 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) { token = '*'; } + if (!strcmp(command,"PING")) + { + token = '*'; + } if (!strcmp(command,"NOTICE")) { snprintf(udp_msg,MAXBUF,"V %s %s",source,data); @@ -2704,7 +2977,6 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) } - char* params = udp_msg + 2; char finalparam[1024]; strcpy(finalparam," :xxxx"); @@ -2764,6 +3036,8 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) char* revision = strtok(NULL," "); char* serverdesc = finalparam+2; + password = password; + WriteOpers("CONNECT from %s (%s) (their port: %d)",servername,tcp_host,atoi(myport)); ircd_connector* cn = serv->FindHost(servername); @@ -2817,7 +3091,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) 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)) + if ((!strcasecmp(Link_ServerName,servername)) && (!strcmp(Link_Pass,password))) { // we have a matching link line - // send a 'diminutive' server message back... @@ -2849,6 +3123,8 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) char* servername = strtok(params," "); char* password = strtok(NULL," "); char* serverdesc = finalparam+2; + + password = password; // 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 @@ -2864,7 +3140,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) char Link_Pass[1024]; char Link_SendPass[1024]; int LinkPort = 0; - + // search for a corresponding block in the config files for (int i = 0; i < ConfValueEnum("link",&config_f); i++) { @@ -2899,8 +3175,6 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) } } } - WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right noe! Possible intrusion attempt!",tcp_host); - return; } } else { @@ -2930,6 +3204,28 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) 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 (int k = 0; k < me[j]->connectors.size(); k++) + { + if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),servername)) + { + char buffer[MAXBUF]; + sprintf(buffer,"E :Access is denied (Server exists in the mesh)"); + serv->SendPacket(buffer,tcp_host); + WriteOpers("CONNECT from %s denied, \"%s\" already exists!",tcp_host,servername); + RemoveServer(tcp_host); + return; + } + } + } + } // search for a corresponding block in the config files for (int i = 0; i < ConfValueEnum("link",&config_f); i++) @@ -2941,7 +3237,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) 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)) + 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 @@ -2955,11 +3251,14 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) 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); sprintf(buffer,"X 0"); serv->SendPacket(buffer,servername); + sprintf(buffer,"s %s %s %lu :%s",ServerName,Link_SendPass,LinkPort,ServerDesc); + serv->SendPacket(buffer,servername); DoSync(me[j],servername); snprintf(buffer,MAXBUF,"H %s",servername); NetSendToAllExcept(servername,buffer); @@ -2970,14 +3269,13 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) } } } - WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right noe! Possible intrusion attempt!",tcp_host); - 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]; sprintf(buffer,"E :Access is denied (no matching link block)"); serv->SendPacket(buffer,tcp_host); @@ -2993,9 +3291,6 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) return; } else { - - serverrec* source_server = NULL; - for (int j = 0; j < 32; j++) { if (me[j] != NULL) @@ -3020,14 +3315,14 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) } } -long duration(char* str) +long duration(const char* str) { char n_field[MAXBUF]; long total = 0; - char* str_end = str + strlen(str); + const char* str_end = str + strlen(str); n_field[0] = 0; - for (char* i = str; i < str_end; i++) + for (char* i = (char*)str; i < str_end; i++) { // if we have digits, build up a string for the value in n_field, // up to 10 digits in size. @@ -3102,6 +3397,34 @@ void handle_kline(char **parameters, int pcnt, userrec *user) apply_lines(); } +void handle_eline(char **parameters, int pcnt, userrec *user) +{ + if (pcnt >= 3) + { + add_eline(duration(parameters[1]),user->nick,parameters[2],parameters[0]); + if (!duration(parameters[1])) + { + WriteOpers("*** %s added permenant E-line for %s.",user->nick,parameters[0]); + } + else + { + WriteOpers("*** %s added timed E-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1])); + } + } + else + { + if (del_eline(parameters[0])) + { + WriteOpers("*** %s Removed E-line on %s.",user->nick,parameters[0]); + } + else + { + WriteServ(user->fd,"NOTICE %s :*** E-Line %s not found in list, try /stats e.",user->nick,parameters[0]); + } + } + // no need to apply the lines for an eline +} + void handle_gline(char **parameters, int pcnt, userrec *user) { char netdata[MAXBUF]; @@ -3109,7 +3432,7 @@ void handle_gline(char **parameters, int pcnt, userrec *user) { add_gline(duration(parameters[1]),user->nick,parameters[2],parameters[0]); // # : - snprintf(netdata,MAXBUF,"# %s %s %ld %ld :%s",parameters[0],user->nick,time(NULL),duration(parameters[1]),parameters[2]); + snprintf(netdata,MAXBUF,"# %s %s %lu %lu :%s",parameters[0],user->nick,(unsigned long)TIME,(unsigned long)duration(parameters[1]),parameters[2]); NetSendToAll(netdata); if (!duration(parameters[1])) {