]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Added ip address to N token for SLINE in services use
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 618365c8b84e33633c2d45d75ae35cab4400fef1..3aa5ecaa89e8c253384a4d7fabf827e56006d875 100644 (file)
@@ -82,6 +82,7 @@ int WHOWAS_MAX = 100;  // default 100 people maximum in the WHOWAS list
 int DieDelay  =  5;
 time_t startup_time = time(NULL);
 int NetBufferSize = 10240; // NetBufferSize used as the buffer size for all read() ops
+extern int MaxWhoResults;
 time_t nb_start = 0;
 
 extern vector<Module*> modules;
@@ -299,7 +300,7 @@ void readfile(file_cache &F, const char* fname)
 
 void ReadConfig(void)
 {
-       char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF];
+       char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF];
        ConnectClass c;
        
        LoadConf(CONFIG_FILE,&config_f);
@@ -319,12 +320,19 @@ void ReadConfig(void)
        ConfValue("die","value",0,DieValue,&config_f);
        ConfValue("options","loglevel",0,dbg,&config_f);
        ConfValue("options","netbuffersize",0,NB,&config_f);
+       ConfValue("options","maxwho",0,MW,&config_f);
        NetBufferSize = atoi(NB);
+       MaxWhoResults = atoi(MW);
        if ((!NetBufferSize) || (NetBufferSize > 65535) || (NetBufferSize < 1024))
        {
                log(DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240.");
                NetBufferSize = 10240;
        }
+       if ((!MaxWhoResults) || (MaxWhoResults > 65535) || (MaxWhoResults < 1))
+       {
+               log(DEFAULT,"No MaxWhoResults specified or size out of range, setting to default of 128.");
+               MaxWhoResults = 128;
+       }
        if (!strcmp(dbg,"debug"))
                LogLevel = DEBUG;
        if (!strcmp(dbg,"verbose"))
@@ -1114,6 +1122,7 @@ char* chanmodes(chanrec *chan)
        }
        if (strcmp(chan->key,""))
        {
+               strncat(sparam," ",MAXBUF);
                strncat(sparam,chan->key,MAXBUF);
        }
        if (chan->limit)
@@ -1840,6 +1849,56 @@ void kill_link(userrec *user,const char* r)
        }
 }
 
+void kill_link_silent(userrec *user,const char* r)
+{
+       user_hash::iterator iter = clientlist.find(user->nick);
+       
+       char reason[MAXBUF];
+       
+       strncpy(reason,r,MAXBUF);
+
+       if (strlen(reason)>MAXQUIT)
+       {
+               reason[MAXQUIT-1] = '\0';
+       }
+
+       log(DEBUG,"kill_link: %s '%s'",user->nick,reason);
+       Write(user->fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason);
+       log(DEBUG,"closing fd %d",user->fd);
+
+       /* bugfix, cant close() a nonblocking socket (sux!) */
+       if (user->registered == 7) {
+               FOREACH_MOD OnUserQuit(user);
+               WriteCommonExcept(user,"QUIT :%s",reason);
+
+               // Q token must go to ALL servers!!!
+               char buffer[MAXBUF];
+               snprintf(buffer,MAXBUF,"Q %s :%s",user->nick,reason);
+               NetSendToAll(buffer);
+       }
+
+       /* push the socket on a stack of sockets due to be closed at the next opportunity
+        * 'Client exited' is an exception to this as it means the client side has already
+        * closed the socket, we don't need to do it.
+        */
+       fd_reap.push_back(user->fd);
+       
+       bool do_purge = false;
+       
+       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);
+       }
+
+       if (user->registered == 7) {
+               purge_empty_chans();
+       }
+}
+
 
 
 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
@@ -2046,7 +2105,7 @@ void AddClient(int socket, char* host, int port, bool iscached, char* ip)
        clientlist[tempnick] = new userrec();
 
        NonBlocking(socket);
-       log(DEBUG,"AddClient: %d %s %d",socket,host,port);
+       log(DEBUG,"AddClient: %d %s %d %s",socket,host,port,ip);
 
        clientlist[tempnick]->fd = socket;
        strncpy(clientlist[tempnick]->nick, tn2,NICKMAX);
@@ -2102,6 +2161,14 @@ void AddClient(int socket, char* host, int port, bool iscached, char* ip)
 
        if (clientlist.size() == MAXCLIENTS)
                kill_link(clientlist[tempnick],"No more connections allowed in this class");
+               
+       char* r = matches_zline(ip);
+       if (r)
+       {
+               char reason[MAXBUF];
+               snprintf(reason,MAXBUF,"Z-Lined: %s",r);
+               kill_link(clientlist[tempnick],reason);
+       }
 }
 
 
@@ -2225,6 +2292,26 @@ void ConnectUser(userrec *user)
                return;
        }
 
+       char match_against[MAXBUF];
+       snprintf(match_against,MAXBUF,"%s@%s",user->ident,user->host);
+       char* r = matches_gline(match_against);
+       if (r)
+       {
+               char reason[MAXBUF];
+               snprintf(reason,MAXBUF,"G-Lined: %s",r);
+               kill_link_silent(user,reason);
+               return;
+       }
+
+       r = matches_kline(user->host);
+       if (r)
+       {
+               char reason[MAXBUF];
+               snprintf(reason,MAXBUF,"K-Lined: %s",r);
+               kill_link_silent(user,reason);
+               return;
+       }
+
        WriteServ(user->fd,"NOTICE Auth :Welcome to \002%s\002!",Network);
        WriteServ(user->fd,"001 %s :Welcome to the %s IRC Network %s!%s@%s",user->nick,Network,user->nick,user->ident,user->host);
        WriteServ(user->fd,"002 %s :Your host is %s, running version %s",user->nick,ServerName,VERSION);
@@ -2237,7 +2324,7 @@ void ConnectUser(userrec *user)
        WriteOpers("*** Client connecting on port %d: %s!%s@%s",user->port,user->nick,user->ident,user->host);
        
        char buffer[MAXBUF];
-       snprintf(buffer,MAXBUF,"N %d %s %s %s %s +%s %s :%s",user->age,user->nick,user->host,user->dhost,user->ident,user->modes,ServerName,user->fullname);
+       snprintf(buffer,MAXBUF,"N %d %s %s %s %s +%s %s %s :%s",user->age,user->nick,user->host,user->dhost,user->ident,user->modes,user->ip,ServerName,user->fullname);
        NetSendToAll(buffer);
 }
 
@@ -2818,7 +2905,7 @@ void DoSync(serverrec* serv, char* tcp_host)
        // send users and channels
        for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
        {
-               snprintf(data,MAXBUF,"N %d %s %s %s %s +%s %s :%s",u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->server,u->second->fullname);
+               snprintf(data,MAXBUF,"N %d %s %s %s %s +%s %s %s :%s",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 (strcmp(chlist(u->second),""))
                {
@@ -2844,6 +2931,8 @@ void DoSync(serverrec* serv, char* tcp_host)
                        serv->SendPacket(data,tcp_host);
                }
        }
+       // sync global zlines, glines, etc
+       sync_xlines(serv,tcp_host);
        snprintf(data,MAXBUF,"F %d",time(NULL));
        serv->SendPacket(data,tcp_host);
        log(DEBUG,"Sent sync");
@@ -3465,7 +3554,7 @@ int InspIRCd(void)
                                }
                                else
                                {
-                                       AddClient(incomingSockfd, resolved, ports[count], iscached, target);
+                                       AddClient(incomingSockfd, resolved, ports[count], iscached, inet_ntoa (client.sin_addr));
                                        log(DEBUG,"InspIRCd: adding client on port %d fd=%d",ports[count],incomingSockfd);
                                }
                                goto label;