X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcommands.cpp;h=bd30e5573417bc1414fc79a81a6558943b061daf;hb=c0fd2894d2de4c3fd0c9e160860f24f290bb52d9;hp=5e5cf66c8eda2542288df799c741d7d6d28148dc;hpb=ab65aa1a5a0379af7bfd672e40875c1e50bd4d12;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/commands.cpp b/src/commands.cpp index 5e5cf66c8..bd30e5573 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -93,7 +93,6 @@ extern bool nofork; extern time_t TIME; -extern std::vector fd_reap; extern std::vector module_names; extern char MyExecutable[1024]; @@ -201,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; @@ -214,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)) @@ -237,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; } @@ -314,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)) @@ -390,12 +385,13 @@ 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); } - purge_empty_chans(); + if (u->registered == 7) + { + purge_empty_chans(u); + } + delete u; } else { @@ -409,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]); } } @@ -431,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; @@ -522,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; @@ -572,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]); } } } @@ -603,7 +600,7 @@ void handle_names(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]); } } @@ -651,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; } @@ -691,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]); } } @@ -739,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; } @@ -771,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]); } } @@ -834,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; @@ -874,13 +870,13 @@ void handle_whois(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]); } } 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]); } } @@ -905,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]; @@ -927,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) @@ -1013,7 +1012,7 @@ void handle_who(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]); } } else @@ -1070,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++) { @@ -1283,7 +1280,7 @@ void handle_modules(char **parameters, int pcnt, userrec *user) strlcat(flagstate,", common",MAXBUF); if (V.Flags & VF_SERVICEPROVIDER) strlcat(flagstate,", service provider",MAXBUF); - if (!strlen(flagstate)) + if (!flagstate[0]) strcpy(flagstate," "); strlcpy(modulename,module_names[i].c_str(),256); if (strchr(user->modes,'o')) @@ -1313,7 +1310,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user) FOREACH_MOD OnStats(*parameters[0]); - if (!strcasecmp(parameters[0],"c")) + if (*parameters[0] == 'c') { for (int i = 0; i < ConfValueEnum("link",&config_f); i++) { @@ -1325,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++) @@ -1335,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++) @@ -1345,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++) { @@ -1354,7 +1351,7 @@ 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++) @@ -1369,33 +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 (!strcmp(parameters[0],"e")) + 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++) { @@ -1412,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()); @@ -1425,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++) { @@ -1440,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++) @@ -1458,7 +1455,7 @@ 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; @@ -1490,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) @@ -1541,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); + } } } @@ -1587,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); @@ -1599,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) { @@ -1609,7 +1648,7 @@ void handle_oper(char **parameters, int pcnt, userrec *user) char TypeName[MAXBUF]; char HostName[MAXBUF]; char TheHost[MAXBUF]; - int i,j; + int j; bool found = false; bool fail2 = false; char global[MAXBUF]; @@ -1622,7 +1661,7 @@ void handle_oper(char **parameters, int pcnt, userrec *user) ConfValue("oper","password",i,Password,&config_f); ConfValue("oper","type",i,OperType,&config_f); ConfValue("oper","host",i,HostName,&config_f); - if ((!strcmp(LoginName,parameters[0])) && (!strcmp(Password,parameters[1])) && (match(TheHost,HostName))) + if ((!strcmp(LoginName,parameters[0])) && (!operstrcmp(Password,parameters[1])) && (match(TheHost,HostName))) { fail2 = true; for (j =0; j < ConfValueEnum("type",&config_f); j++) @@ -1659,6 +1698,7 @@ void handle_oper(char **parameters, int pcnt, userrec *user) NetSendToAll(global); FOREACH_MOD OnOper(user); log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType); + AddOper(user); } } else @@ -1691,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; @@ -1749,7 +1789,7 @@ 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); @@ -1970,23 +2010,25 @@ void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* char* nick = NULL; char* channel = NULL; char* reason = NULL; - if (strchr(params,':')) - { - nick = strtok(params," "); - channel = strtok(NULL," :"); - reason = strtok(NULL,"\r\n"); - reason++; - } - else + 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); if ((user) && (channel) && (reason)) { - if (strcmp(reason,"")) + if ((!reason) && (*reason != '\0')) { del_channel(user,channel,reason,true); } @@ -2040,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; } } @@ -2056,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; @@ -2078,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; @@ -2187,6 +2230,7 @@ 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; @@ -2195,9 +2239,14 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* 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) @@ -2406,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) { @@ -2417,6 +2466,7 @@ 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"); + 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. @@ -2458,6 +2508,7 @@ 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"); + 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. @@ -2500,6 +2551,7 @@ 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"); + 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. @@ -2560,7 +2612,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve // 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; // ~ @@ -2738,7 +2790,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve 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 '/': @@ -2800,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); @@ -2811,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; @@ -2920,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"); @@ -2980,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); @@ -3065,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 @@ -3080,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++) { @@ -3115,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 { @@ -3147,7 +3205,27 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv) char Link_SendPass[1024]; int LinkPort = 0; - log(DEBUG,"U-token linked server detected."); + 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++) @@ -3173,6 +3251,7 @@ 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); @@ -3190,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); @@ -3213,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) @@ -3357,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,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])) {