#include "wildcard.h"
#include "message.h"
#include "mode.h"
+#include "xline.h"
#ifdef GCC3
#define nspace __gnu_cxx
extern FILE *log_file;
+const long duration_m = 60;
+const long duration_h = duration_m * 60;
+const long duration_d = duration_h * 24;
+const long duration_w = duration_d * 7;
+const long duration_y = duration_w * 52;
+
namespace nspace
{
template<> struct nspace::hash<in_addr>
parameters[0][1] = '\0';
}
+ if (!strcmp(parameters[0],"k"))
+ {
+ stats_k(user);
+ }
+
+ if (!strcmp(parameters[0],"g"))
+ {
+ stats_g(user);
+ }
+
+ if (!strcmp(parameters[0],"q"))
+ {
+ stats_q(user);
+ }
+
+ if (!strcmp(parameters[0],"Z"))
+ {
+ stats_z(user);
+ }
+
/* stats m (list number of times each command has been used, plus bytecount) */
- if (!strcasecmp(parameters[0],"m"))
+ if (!strcmp(parameters[0],"m"))
{
for (int i = 0; i < cmdlist.size(); i++)
{
}
/* stats z (debug and memory info) */
- if (!strcasecmp(parameters[0],"z"))
+ if (!strcmp(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());
}
/* stats o */
- if (!strcasecmp(parameters[0],"o"))
+ if (!strcmp(parameters[0],"o"))
{
for (int i = 0; i < ConfValueEnum("oper",&config_f); i++)
{
}
/* stats l (show user I/O stats) */
- if (!strcasecmp(parameters[0],"l"))
+ if (!strcmp(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++)
}
/* stats u (show server uptime) */
- if (!strcasecmp(parameters[0],"u"))
+ if (!strcmp(parameters[0],"u"))
{
time_t current_time = 0;
current_time = time(NULL);
WriteServ(user->fd,"007 %s :End of /MAP",user->nick);
}
+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);
+ if (!strcasecmp(server,ServName))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
void handle_oper(char **parameters, int pcnt, userrec *user)
{
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);
for (j =0; j < ConfValueEnum("type",&config_f); j++)
{
ConfValue("type","name",j,TypeName,&config_f);
*parameters[0]++;
}
}
+ if (matches_qline(parameters[0]))
+ {
+ WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
+ WriteServ(user->fd,"432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
+ return;
+ }
if ((Find(parameters[0])) && (Find(parameters[0]) != user))
{
WriteServ(user->fd,"433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
if (user->registered == 7)
{
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnUserPreNick(user,parameters[0]));
+ if (MOD_RESULT) {
+ // if a module returns true, the nick change is silently forbidden.
+ return;
+ }
+
WriteCommon(user,"NICK %s",parameters[0]);
// Q token must go to ALL servers!!!
/* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
ConnectUser(user);
}
- log(DEBUG,"exit nickchange: %s",user->nick);
}
WriteChannelLocal(c,u,"TOPIC %s :%s",c->name,topic);
strncpy(c->topic,topic,MAXTOPIC);
strncpy(c->setby,u->nick,NICKMAX);
+ c->topicset = time(NULL);
}
}
strncpy(target,parameter,MAXBUF);
while (parameter)
{
+ if (parameter[0] == ':')
+ parameter++;
pars[index++] = parameter;
parameter = strtok(NULL," ");
}
+ log(DEBUG,"*** MODE: %s %s",pars[0],pars[1]);
merge_mode(pars,index);
if (FindChan(target))
{
}
if (Find(target))
{
- WriteTo(NULL,Find(target),"MODE %s",original);
+ Write(Find(target)->fd,":%s MODE %s",ServerName,original);
}
}
if (user)
{
WriteCommon(user,"NICK %s",newnick);
+ if (is_uline(tcp_host))
+ {
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnUserPreNick(user,newnick));
+ if (MOD_RESULT) {
+ // if a module returns true, the nick change couldnt be allowed
+ kill_link(user,"Nickname collision");
+ return;
+ }
+ if (matches_qline(newnick))
+ {
+ kill_link(user,"Nickname collision");
+ return;
+ }
+
+ // broadcast this because its a services thingy
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"n %s %s",user->nick,newnick);
+ NetSendToAll(buffer);
+ }
user = ReHashNick(user->nick, newnick);
if (!user) return;
if (!user->nick) return;
if ((s) && (d) && (c))
{
kick_channel(s,d,c,reason);
+ return;
+ }
+ d = Find(channel);
+ c = FindChan(dest);
+ if ((s) && (d) && (c))
+ {
+ kick_channel(s,d,c,reason);
+ return;
}
}
}
}
+void handle_H(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ log(DEBUG,"Adding ULined server %s to my map",params);
+ ircd_connector s;
+ s.SetState(STATE_DISCONNECTED);
+ s.SetServerName(params);
+ source->connectors.push_back(s);
+ WriteOpers("Non-Mesh server %s has joined the network",params);
+}
void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
{
{
char* server = strtok(params," ");
char* data = strtok(NULL,"\r\n");
+ if ((!data) || (!server))
+ {
+ log(DEBUG,"Someones playing silly buggers, attempting to send to a null server or send a null message (BUG?)");
+ return;
+ }
+
log(DEBUG,"Forwarded packet '%s' to '%s'",data,server);
NetSendToOne(server,data);
}
void handle_amp(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
{
log(DEBUG,"Netsplit! %s split from mesh, removing!",params);
+ WriteOpers("*** NOTICE - Controlled netsplit: %s split from %s",params,ServerName);
bool go_again = true;
while (go_again)
{
long authcookie;
+void handle_hash(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ log(DEBUG,"Adding G-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ char* create_time = strtok(NULL," ");
+ char* duration = strtok(NULL," :");
+ char* reason = strtok(NULL,"\r\n");
+ add_gline(atoi(duration),who,reason,mask);
+ // we must update the creation time on this gline
+ // now that we've added it, or it wont expire at the right time.
+ gline_set_creation_time(mask,atoi(create_time));
+ if (!atoi(duration))
+ {
+ WriteOpers("*** %s Added permenant G-Line on %s.",who,mask);
+ }
+ else
+ {
+ WriteOpers("*** %s Added timed G-Line on %s to expire in %d seconds.",who,mask,atoi(duration));
+ }
+ apply_lines();
+}
+
+void handle_dot(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ log(DEBUG,"Removing G-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ if (mask)
+ {
+ if (del_gline(mask))
+ {
+ if (who)
+ {
+ WriteOpers("*** %s Removed G-line on %s.",who,mask);
+ }
+ }
+ }
+}
+
+void handle_add_sqline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ // { <mask> <who-set-it> <time-set> <duration> :<reason>
+ log(DEBUG,"Adding Q-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ char* create_time = strtok(NULL," ");
+ char* duration = strtok(NULL," :");
+ char* reason = strtok(NULL,"\r\n");
+ add_qline(atoi(duration),who,reason,mask);
+ // we must update the creation time on this gline
+ // now that we've added it, or it wont expire at the right time.
+ qline_set_creation_time(mask,atoi(create_time));
+ qline_make_global(mask);
+ if (!atoi(duration))
+ {
+ WriteOpers("*** %s Added permenant Q-Line on %s.",who,mask);
+ }
+ else
+ {
+ WriteOpers("*** %s Added timed Q-Line on %s to expire in %d seconds.",who,mask,atoi(duration));
+ }
+ apply_lines();
+}
+
+void handle_del_sqline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ log(DEBUG,"Removing Q-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ if (mask)
+ {
+ if (del_qline(mask))
+ {
+ if (who)
+ {
+ WriteOpers("*** %s Removed Q-line on %s.",who,mask);
+ }
+ }
+ }
+}
+
+void handle_add_szline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ // } <mask> <who-set-it> <time-set> <duration> :<reason>
+ log(DEBUG,"Adding Z-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ char* create_time = strtok(NULL," ");
+ char* duration = strtok(NULL," :");
+ char* reason = strtok(NULL,"\r\n");
+ add_zline(atoi(duration),who,reason,mask);
+ // we must update the creation time on this gline
+ // now that we've added it, or it wont expire at the right time.
+ zline_set_creation_time(mask,atoi(create_time));
+ zline_make_global(mask);
+ if (!atoi(duration))
+ {
+ WriteOpers("*** %s Added permenant Z-Line on %s.",who,mask);
+ }
+ else
+ {
+ WriteOpers("*** %s Added timed Z-Line on %s to expire in %d seconds.",who,mask,atoi(duration));
+ }
+ apply_lines();
+}
+
+void handle_del_szline(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
+{
+ log(DEBUG,"Removing Z-line");
+ char* mask = strtok(params," ");
+ char* who = strtok(NULL," ");
+ if (mask)
+ {
+ if (del_zline(mask))
+ {
+ if (who)
+ {
+ WriteOpers("*** %s Removed Q-line on %s.",who,mask);
+ }
+ }
+ }
+}
+
void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host,char* ipaddr,int port)
{
case 'Q':
handle_Q(token,params,source,reply,tcp_host);
break;
+ // H <SERVER>
+ // introduce non-meshable server (such as a services server)
+ case 'H':
+ handle_H(token,params,source,reply,tcp_host);
+ break;
// K <SOURCE> <DEST> :<REASON>
// remote kill
case 'K':
case '@':
handle_AT(token,params,source,reply,tcp_host);
break;
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ // add gline
+ case '#':
+ handle_hash(token,params,source,reply,tcp_host);
+ break;
+ // . <mask> <who>
+ // remove gline
+ case '.':
+ handle_dot(token,params,source,reply,tcp_host);
+ break;
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ // add gline
+ case '{':
+ handle_add_sqline(token,params,source,reply,tcp_host);
+ break;
+ // . <mask> <who>
+ // remove gline
+ case '[':
+ handle_del_sqline(token,params,source,reply,tcp_host);
+ break;
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ // add gline
+ case '}':
+ handle_add_szline(token,params,source,reply,tcp_host);
+ break;
+ // . <mask> <who>
+ // remove gline
+ case ']':
+ handle_del_szline(token,params,source,reply,tcp_host);
+ break;
// F <TS>
// end netburst
case 'F':
void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
{
+ if ((!strncmp(udp_msg,"USER ",5)) || (!strncmp(udp_msg,"NICK ",5)))
+ {
+ // a user on a server port, just close their connection.
+ RemoveServer(tcp_host);
+ return;
+ }
+
char response[10240];
char token = udp_msg[0];
+ char* old = udp_msg;
if (token == ':') // leading :servername or details - strip them off (services does this, sucky)
{
+ char* src = udp_msg+1;
while (udp_msg[0] != ' ')
udp_msg++;
+ udp_msg[0] = 0;
udp_msg++;
- token = udp_msg[0];
+ char* comd = udp_msg;
+ while (udp_msg[0] != ' ')
+ udp_msg++;
+ udp_msg[0] = 0;
+ udp_msg++;
+ char data[MAXBUF];
+ char source[MAXBUF];
+ char command[MAXBUF];
+ strcpy(data,udp_msg);
+ strcpy(source,src);
+ strcpy(command,comd);
+ udp_msg = old;
+
+ // unused numeric:
+ // :services-dev.chatspike.net 433 Craig Craig :Nickname is registered to someone else
+ if (!strcmp(command,"433"))
+ {
+ token = '*';
+ }
+ if (!strcmp(command,"432"))
+ {
+ token = '*';
+ }
+ if (!strcmp(command,"NOTICE"))
+ {
+ snprintf(udp_msg,MAXBUF,"V %s %s",source,data);
+ log(DEBUG,"Rewrote NOTICE from services to: '%s'",udp_msg);
+ token = udp_msg[0];
+ }
+ if (!strcmp(command,"QUIT"))
+ {
+ if ((!udp_msg) || (!strcmp(data,"")) || (strcmp(data,":")))
+ {
+ strcpy(data,":No reason");
+ }
+ if (!strcmp(data,":"))
+ {
+ strcpy(data,":No reason");
+ }
+ snprintf(udp_msg,MAXBUF,"Q %s %s",source,data);
+ log(DEBUG,"Rewrote QUIT from services to: '%s'",udp_msg);
+ token = udp_msg[0];
+ }
+ if (!strcmp(command,"SQUIT"))
+ {
+ snprintf(udp_msg,MAXBUF,"& %s",source);
+ log(DEBUG,"Rewrote SQUIT from services to: '%s'",udp_msg);
+ token = udp_msg[0];
+ }
+ if (!strcmp(command,"SVSMODE"))
+ {
+ snprintf(udp_msg,MAXBUF,"M %s",data);
+ log(DEBUG,"Rewrote SVSMODE from services to: '%s'",udp_msg);
+ token = udp_msg[0];
+ }
+ if (!strcmp(command,"SVS2MODE"))
+ {
+ snprintf(udp_msg,MAXBUF,"M %s",data);
+ log(DEBUG,"Rewrote SVSMODE from services to: '%s'",udp_msg);
+ token = udp_msg[0];
+ }
+ // todo: this wont work without u:lines
+ // in give_ops etc allow nick on a u:lined serv to do just about anything
+ if (!strcmp(command,"MODE"))
+ {
+ snprintf(udp_msg,MAXBUF,"m %s %s",source,data);
+ log(DEBUG,"Rewrote MODE from services to: '%s'",udp_msg);
+ token = udp_msg[0];
+ }
+ if (!strcmp(command,"KICK"))
+ {
+ snprintf(udp_msg,MAXBUF,"k %s %s",source,data);
+ log(DEBUG,"Rewrote KICK from services to: '%s'",udp_msg);
+ token = udp_msg[0];
+ }
+ if (!strcmp(command,"SVSJOIN"))
+ {
+ snprintf(udp_msg,MAXBUF,"J %s",data);
+ NetSendToOne(tcp_host,udp_msg);
+ char* nick = strtok(data," ");
+ char* chan = strtok(NULL," ");
+ log(DEBUG,"Rewrote SVSJOIN from services to: '%s'",udp_msg);
+ userrec* u = Find(nick);
+ if (u)
+ {
+ add_channel(u,chan,"",true);
+ }
+ token = udp_msg[0];
+ }
+
}
{
if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),tcp_host))
{
- char buffer[MAXBUF];
+ char buffer[MAXBUF];
me[j]->connectors[k].SetDescription(serverdesc);
me[j]->connectors[k].SetServerName(servername);
- me[j]->connectors[k].SetState(STATE_CONNECTED);
+ me[j]->connectors[k].SetState(STATE_SERVICES);
sprintf(buffer,"X 0");
- serv->SendPacket(buffer,tcp_host);
- DoSync(me[j],tcp_host);
+ serv->SendPacket(buffer,servername);
+ DoSync(me[j],servername);
NetSendMyRoutingTable();
+ sprintf(buffer,"H %s",servername);
+ NetSendToAllExcept(servername,buffer);
+ WriteOpers("Non-Mesh server %s has joined the network",servername);
return;
}
}
log(DEBUG,"Servers are: '%s' '%s'",tcp_host,me[j]->connectors[x].GetServerName().c_str());
if (!strcasecmp(me[j]->connectors[x].GetServerName().c_str(),tcp_host))
{
- if (me[j]->connectors[x].GetState() == STATE_CONNECTED)
+ if ((me[j]->connectors[x].GetState() == STATE_CONNECTED) || (me[j]->connectors[x].GetState() == STATE_SERVICES))
{
// found a valid ircd_connector.
process_restricted_commands(token,params,me[j],serv,tcp_host,me[j]->connectors[x].GetServerIP(),me[j]->connectors[x].GetServerPort());
}
}
+long duration(char* str)
+{
+ char n_field[MAXBUF];
+ long total = 0;
+ char* str_end = str + strlen(str);
+ n_field[0] = 0;
+
+ for (char* i = 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.
+ if ((*i >= '0') && (*i <= '9'))
+ {
+ strncat(n_field,i,10);
+ }
+ else
+ {
+ // we dont have a digit, check for numeric tokens
+ switch (tolower(*i))
+ {
+ case 's':
+ total += atoi(n_field);
+ break;
+
+ case 'm':
+ total += (atoi(n_field)*duration_m);
+ break;
+
+ case 'h':
+ total += (atoi(n_field)*duration_h);
+ break;
+
+ case 'd':
+ total += (atoi(n_field)*duration_d);
+ break;
+
+ case 'w':
+ total += (atoi(n_field)*duration_w);
+ break;
+
+ case 'y':
+ total += (atoi(n_field)*duration_y);
+ break;
+ }
+ n_field[0] = 0;
+ }
+ }
+ // add trailing seconds
+ total += atoi(n_field);
+
+ return total;
+}
+
+
+void handle_kline(char **parameters, int pcnt, userrec *user)
+{
+ if (pcnt >= 3)
+ {
+ add_kline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant K-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed K-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_kline(parameters[0]))
+ {
+ WriteOpers("*** %s Removed K-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** K-Line %s not found in list, try /stats k.",user->nick,parameters[0]);
+ }
+ }
+ apply_lines();
+}
+
+void handle_gline(char **parameters, int pcnt, userrec *user)
+{
+ char netdata[MAXBUF];
+ if (pcnt >= 3)
+ {
+ add_gline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ // # <mask> <who-set-it> <time-set> <duration> :<reason>
+ snprintf(netdata,MAXBUF,"# %s %s %ld %ld :%s",parameters[0],user->nick,time(NULL),duration(parameters[1]),parameters[2]);
+ NetSendToAll(netdata);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant G-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed G-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_gline(parameters[0]))
+ {
+ // . <mask> <who-removed-it>
+ snprintf(netdata,MAXBUF,". %s %s",parameters[0],user->nick);
+ WriteOpers("*** %s Removed G-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** G-Line %s not found in list, try /stats g.",user->nick,parameters[0]);
+ }
+ }
+ apply_lines();
+}
+
+void handle_zline(char **parameters, int pcnt, userrec *user)
+{
+ if (pcnt >= 3)
+ {
+ add_zline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant Z-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed Z-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_zline(parameters[0]))
+ {
+ WriteOpers("*** %s Removed Z-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** Z-Line %s not found in list, try /stats Z.",user->nick,parameters[0]);
+ }
+ }
+ apply_lines();
+}
+
+void handle_qline(char **parameters, int pcnt, userrec *user)
+{
+ if (pcnt >= 3)
+ {
+ add_qline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ if (!duration(parameters[1]))
+ {
+ WriteOpers("*** %s added permenant Q-line for %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteOpers("*** %s added timed Q-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
+ }
+ }
+ else
+ {
+ if (del_qline(parameters[0]))
+ {
+ WriteOpers("*** %s Removed Q-line on %s.",user->nick,parameters[0]);
+ }
+ else
+ {
+ WriteServ(user->fd,"NOTICE %s :*** Q-Line %s not found in list, try /stats k.",user->nick,parameters[0]);
+ }
+ }
+ apply_lines();
+}
+
+