]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/xline.cpp
Signed octets in dns forward lookup! GAH
[user/henk/code/inspircd.git] / src / xline.cpp
index 716153b0ca8e389e30c725bddaeac66f673c4307..7a6db9a61cd857194ea68d05d0725b49d9fcfb55 100644 (file)
  * ---------------------------------------------------
  */
 
+using namespace std;
+
+#include "inspircd_config.h"
 #include "inspircd.h"
 #include "inspircd_io.h"
 #include "inspircd_util.h"
-#include "inspircd_config.h"
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/utsname.h>
-#include <cstdio>
 #include <time.h>
 #include <string>
 #ifdef GCC3
 #include <map>
 #include <sstream>
 #include <vector>
-#include <errno.h>
 #include <deque>
-#include <errno.h>
-#include <unistd.h>
-#include <sched.h>
-#include "connection.h"
 #include "users.h"
-#include "servers.h"
 #include "ctables.h"
 #include "globals.h"
 #include "modules.h"
 #include "commands.h"
 #include "xline.h"
 #include "inspstring.h"
-
-#ifdef GCC3
-#define nspace __gnu_cxx
-#else
-#define nspace std
-#endif
-
-
-using namespace std;
+#include "helperfuncs.h"
+#include "hashcomp.h"
 
 extern int MODCOUNT;
 extern std::vector<Module*> modules;
@@ -88,94 +74,27 @@ extern time_t startup_time;
 extern int NetBufferSize;
 extern time_t nb_start;
 
-extern std::vector<int> fd_reap;
 extern std::vector<std::string> module_names;
 
 extern int boundPortCount;
 extern int portCount;
-extern int UDPportCount;
+
 extern int ports[MAXSOCKS];
-extern int defaultRoute;
 
-extern std::vector<long> auth_cookies;
 extern std::stringstream config_f;
 
-extern serverrec* me[32];
-
 extern FILE *log_file;
 
-namespace nspace
-{
-#ifdef GCC34
-       template<> struct hash<in_addr>
-#else
-       template<> struct nspace::hash<in_addr>
-#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<string>
-#else
-       template<> struct nspace::hash<string>
-#endif
-       {
-               size_t operator()(const string &s) const
-               {
-                       char a[MAXBUF];
-                       static struct hash<const char *> strhash;
-                       strlcpy(a,s.c_str(),MAXBUF);
-                       strlower(a);
-                       return strhash(a);
-               }
-       };
-}      
-
-
-struct StrHashComp
-{
-
-       bool operator()(const string& s1, const string& s2) const
-       {
-               char a[MAXBUF],b[MAXBUF];
-               strlcpy(a,s1.c_str(),MAXBUF);
-               strlcpy(b,s2.c_str(),MAXBUF);
-               return (strcasecmp(a,b) == 0);
-       }
-
-};
-
-struct InAddr_HashComp
-{
-
-       bool operator()(const in_addr &s1, const in_addr &s2) const
-       {
-               size_t q;
-               size_t p;
-               
-               memcpy(&q,&s1,sizeof(size_t));
-               memcpy(&p,&s2,sizeof(size_t));
-               
-               return (q == p);
-       }
-
-};
-
-
-typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, StrHashComp> user_hash;
-typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, StrHashComp> chan_hash;
-typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, InAddr_HashComp> address_cache;
+typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
+typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, irc::StrHashComp> chan_hash;
+typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp> address_cache;
+typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp> whowas_hash;
 typedef std::deque<command_t> command_table;
 
 
 extern user_hash clientlist;
 extern chan_hash chanlist;
-extern user_hash whowas;
+extern whowas_hash whowas;
 extern command_table cmdlist;
 extern file_cache MOTD;
 extern file_cache RULES;
@@ -240,9 +159,9 @@ void add_gline(long duration, const char* source,const char* reason,const char*
        del_gline(hostmask);
        GLine item;
        item.duration = duration;
-       strlcpy(item.hostmask,hostmask,MAXBUF);
+       strlcpy(item.hostmask,hostmask,199);
        strlcpy(item.reason,reason,MAXBUF);
-       strlcpy(item.source,source,MAXBUF);
+       strlcpy(item.source,source,255);
        item.n_matches = 0;
        item.set_time = TIME;
        glines.push_back(item);
@@ -255,9 +174,9 @@ void add_eline(long duration, const char* source, const char* reason, const char
         del_eline(hostmask);
         ELine item;
         item.duration = duration;
-        strlcpy(item.hostmask,hostmask,MAXBUF);
+        strlcpy(item.hostmask,hostmask,199);
         strlcpy(item.reason,reason,MAXBUF);
-        strlcpy(item.source,source,MAXBUF);
+        strlcpy(item.source,source,255);
         item.n_matches = 0;
         item.set_time = TIME;
         elines.push_back(item);
@@ -270,9 +189,9 @@ void add_qline(long duration, const char* source, const char* reason, const char
        del_qline(nickname);
        QLine item;
        item.duration = duration;
-       strlcpy(item.nick,nickname,MAXBUF);
+       strlcpy(item.nick,nickname,63);
        strlcpy(item.reason,reason,MAXBUF);
-       strlcpy(item.source,source,MAXBUF);
+       strlcpy(item.source,source,255);
        item.n_matches = 0;
        item.is_global = false;
        item.set_time = TIME;
@@ -286,9 +205,15 @@ void add_zline(long duration, const char* source, const char* reason, const char
        del_zline(ipaddr);
        ZLine item;
        item.duration = duration;
-       strlcpy(item.ipaddr,ipaddr,MAXBUF);
+       if (strchr(ipaddr,'@'))
+       {
+               while (*ipaddr != '@')
+                       ipaddr++;
+               ipaddr++;
+       }
+       strlcpy(item.ipaddr,ipaddr,39);
        strlcpy(item.reason,reason,MAXBUF);
-       strlcpy(item.source,source,MAXBUF);
+       strlcpy(item.source,source,255);
        item.n_matches = 0;
        item.is_global = false;
        item.set_time = TIME;
@@ -302,9 +227,9 @@ void add_kline(long duration, const char* source, const char* reason, const char
        del_kline(hostmask);
        KLine item;
        item.duration = duration;
-       strlcpy(item.hostmask,hostmask,MAXBUF);
+       strlcpy(item.hostmask,hostmask,200);
        strlcpy(item.reason,reason,MAXBUF);
-       strlcpy(item.source,source,MAXBUF);
+       strlcpy(item.source,source,255);
        item.n_matches = 0;
        item.set_time = TIME;
        klines.push_back(item);
@@ -381,36 +306,6 @@ bool zline_make_global(const char* ipaddr)
        return false;
 }
 
-void sync_xlines(serverrec* serv, char* tcp_host)
-{
-       char data[MAXBUF];
-       
-       // for zlines and qlines, we should first check if theyre global...
-       for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
-       {
-               if (i->is_global)
-               {
-                       snprintf(data,MAXBUF,"} %s %s %ld %ld :%s",i->ipaddr,i->source,i->set_time,i->duration,i->reason);
-                       serv->SendPacket(data,tcp_host);
-               }
-       }
-       for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
-       {
-               if (i->is_global)
-               {
-                       snprintf(data,MAXBUF,"{ %s %s %ld %ld :%s",i->nick,i->source,i->set_time,i->duration,i->reason);
-                       serv->SendPacket(data,tcp_host);
-               }
-       }
-       // glines are always global, so no need to check
-       for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
-       {
-               snprintf(data,MAXBUF,"# %s %s %ld %ld :%s",i->hostmask,i->source,i->set_time,i->duration,i->reason);
-               serv->SendPacket(data,tcp_host);
-       }
-}
-
-
 // deletes a z:line, returns true if the line existed and was removed
 
 bool del_zline(const char* ipaddr)
@@ -570,6 +465,12 @@ void expire_lines()
        
        // because we mess up an iterator when we remove from the vector, we must bail from
        // the loop early if we delete an item, therefore this outer while loop is required.
+       //
+       // 30/11/2005-- I can imagine that if we get a large number of *lines, this would perform dog slow.
+       // While we try and think of a better solution, for now I've simply split the loops up, instead of
+       // one huge while () -- this means if we remove a g-line, we only need to re-check glines, not z/g/.
+       // lines too, hopefully a little faster, even if it looks a little messier ;) --w00t
+
        while (go_again)
        {
                go_again = false;
@@ -584,6 +485,13 @@ void expire_lines()
                                break;
                        }
                }
+       }
+
+       go_again = true;
+
+       while (go_again)
+       {
+               go_again = false;
 
                 for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
                 {
@@ -595,6 +503,13 @@ void expire_lines()
                                 break;
                         }
                 }
+       }
+
+       go_again = true;
+
+       while (go_again)
+       {
+               go_again = false;
 
                for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
                {
@@ -606,6 +521,13 @@ void expire_lines()
                                break;
                        }
                }
+       }
+
+       go_again = true;
+
+       while (go_again)
+       {
+               go_again = false;
 
                for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
                {
@@ -617,6 +539,14 @@ void expire_lines()
                                break;
                        }
                }
+       }
+
+       go_again = true;
+
+
+       while (go_again)
+       {
+               go_again = false;
 
                for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
                {
@@ -661,7 +591,7 @@ void apply_lines()
                                        char* check = matches_gline(host);
                                        if (check)
                                        {
-                                               WriteOpers("*** User %s matches G-Line: %s",u->second->nick,check);
+                                               WriteOpers("*** User %s matches G-Line: %s",u->second->registered == 7 ? u->second->nick:"<unknown>",check);
                                                snprintf(reason,MAXBUF,"G-Lined: %s",check);
                                                kill_link(u->second,reason);
                                                go_again = true;
@@ -673,7 +603,7 @@ void apply_lines()
                                        char* check = matches_kline(host);
                                        if (check)
                                        {
-                                               WriteOpers("*** User %s matches K-Line: %s",u->second->nick,check);
+                                               WriteOpers("*** User %s matches K-Line: %s",u->second->registered == 7 ? u->second->nick:"<unknown>",check);
                                                snprintf(reason,MAXBUF,"K-Lined: %s",check);
                                                kill_link(u->second,reason);
                                                go_again = true;
@@ -686,7 +616,7 @@ void apply_lines()
                                        if (check)
                                        {
                                                snprintf(reason,MAXBUF,"Matched Q-Lined nick: %s",check);
-                                               WriteOpers("*** Q-Lined nickname %s from %s: %s",u->second->nick,u->second->host,check);
+                                               WriteOpers("*** Q-Lined nickname %s from %s: %s",u->second->registered == 7 ? u->second->nick:"<unknown>",u->second->host,check);
                                                kill_link(u->second,reason);
                                                go_again = true;
                                                break;
@@ -698,7 +628,7 @@ void apply_lines()
                                        if (check)
                                        {
                                                snprintf(reason,MAXBUF,"Z-Lined: %s",check);
-                                               WriteOpers("*** User %s matches Z-Line: %s",u->second->nick,u->second->host,check);
+                                               WriteOpers("*** User %s matches Z-Line: %s",u->second->registered == 7 ? u->second->nick:"<unknown>",u->second->host,check);
                                                kill_link(u->second,reason);
                                                go_again = true;
                                                break;