]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Added E:Lines, a form of ban exception that can prevent opers, netadmins etc from...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 4 Apr 2005 17:55:48 +0000 (17:55 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 4 Apr 2005 17:55:48 +0000 (17:55 +0000)
either in the config or by an oper with the correct permissions to use the /ELINE command

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@975 e03df62e-2008-0410-955e-edbf42e46eb7

docs/helpop.conf.example
docs/inspircd.conf.example
include/commands.h
include/xline.h
src/commands.cpp
src/inspircd.cpp
src/xline.cpp

index 583108b23736e851caec86911871d9f841c85852..522250242fd74d607875247a188e7f06cca2c5b5 100644 (file)
        line18="U  Show u-lined servers"
        line19="P  Show online opers and their idle times"
        line20="I  Show connect class permissions"
-       line21="-"
-       line22="Note that all /STATS use is broadcast to online IRC operators.">
+       line21="e  Show e-lines (local ban exemptions)"
+       line22="-"
+       line23="Note that all /STATS use is broadcast to online IRC operators.">
 
 <kline line1="/KLINE [user@host] {[duration] :[reason]}"
        line2="Sets or removes a k-line (host based ban) on a host and ident mask."
index 22031e957979781786802d25a53d9b521870a4c7..39fa8fe1e0c0f4c15162d940f62d15c19f3056b2 100644 (file)
 
 <pid file="/path/to/inspircd.pid">
 
+#-#-#-#-#-#-#-#-#-#-#-#-#- BANLIST LIMITS #-#-#-#-#-#-#-#-#-#-#-#-#-#-#
+#                                                                     #
+# Use these tags to customise the ban limits on a per channel basis.  #
+# the tags are read from top to bottom, and any tag found which       #
+# matches the channels name applies the banlimit to that channel.     #
+# It is advisable to put an entry with the channel as '*' at the      #
+# bottom of the list. If none are specified or no maxbans tag is      #
+# matched, the banlist size defaults to 64 entries.                   #
+#                                                                     #
+
+<banlist chan="#morons" limit="128">
+<banlist chan="*" limit="69">
 
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-  RTFM LINE  -#-#-#-#-#-#-#-#-#-#-#-#-#-#
 #                                                                     #
 # host         -          ident@hostname (wildcards possible)         #
 # reason       -          Reason to display on disconnection          #
 #                                                                     #
+# exception lines define a hostmask that is excempt from [kzg]lines   #
+#                                                                     #
+# host         -          ident@hostname (wildcards possible)         #
+# reason       -          Reason, shown only in /stats e              #
+#                                                                     #
 
 <badip ipmask="69.69.69.69" reason="No porn here thanks.">
 
 <badhost host="*@hundredz.n.hundredz.o.1337.kiddies.com" reason="Too many 1337 kiddiots">
 <badhost host="*@localhost" reason="No irc from localhost!">
 
+<exception host="*@ircop.host.com" reason="Opers hostname">
+
 #-#-#-#-#-#-#-#-#-#-#-  ALIAS DEFINITIONS  -#-#-#-#-#-#-#-#-#-#-#-#-#-#
 #                                                                     #
 # If you have the m_alias.so module loaded, you may also define       #
index f1c383e083c0cb042835927091a30e5b9b01ce37..1242671b3fdbca89bc52443e6900c633d391637e 100644 (file)
@@ -77,6 +77,7 @@ void handle_kline(char **parameters, int pcnt, userrec *user);
 void handle_gline(char **parameters, int pcnt, userrec *user);
 void handle_zline(char **parameters, int pcnt, userrec *user);
 void handle_qline(char **parameters, int pcnt, userrec *user);
+void handle_eline(char **parameters, int pcnt, userrec *user);
 void handle_server(char **parameters, int pcnt, userrec *user);
 
 /** Special functions for processing server to server traffic
index 87f88518fca89f0a45a66a352fd238d11a0b6a41..b5163ee58fb256a38a444673492e83d75dba21a8 100644 (file)
@@ -79,6 +79,15 @@ class GLine : public XLine
        char hostmask[MAXBUF];
 };
 
+class ELine : public XLine
+{
+  public:
+        /** Hostmask (ident@host) to match against
+         * May contain wildcards.
+         */
+        char hostmask[MAXBUF];
+};
+
 /** ZLine class
  */
 class ZLine : public XLine
@@ -115,16 +124,19 @@ void add_gline(long duration, char* source, char* reason, char* hostmask);
 void add_qline(long duration, char* source, char* reason, char* nickname);
 void add_zline(long duration, char* source, char* reason, char* ipaddr);
 void add_kline(long duration, char* source, char* reason, char* hostmask);
+void add_eline(long duration, char* source, char* reason, char* hostmask);
 
 bool del_gline(char* hostmask);
 bool del_qline(char* nickname);
 bool del_zline(char* ipaddr);
 bool del_kline(char* hostmask);
+bool del_eline(char* hostmask);
 
 char* matches_qline(const char* nick);
 char* matches_gline(const char* host);
 char* matches_zline(const char* ipaddr);
 char* matches_kline(const char* host);
+char* matches_exception(const char* host);
 
 void expire_lines();
 void apply_lines();
@@ -133,6 +145,7 @@ void stats_k(userrec* user);
 void stats_g(userrec* user);
 void stats_q(userrec* user);
 void stats_z(userrec* user);
+void stats_e(userrec* user);
 
 void gline_set_creation_time(char* host, time_t create_time);
 void qline_set_creation_time(char* nick, time_t create_time);
@@ -144,5 +157,3 @@ bool qline_make_global(char* nickname);
 void sync_xlines(serverrec* serv, char* tcp_host);
 
 #endif
-
-
index 75f0dd86dd6ccb72143cf0e69fc1183662a42697..2ae4e0049ebc46940fc3850506ce550285876736 100644 (file)
@@ -1293,6 +1293,11 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
                stats_z(user);
        }
 
+       if (!strcmp(parameters[0],"e"))
+       {
+               stats_e(user);
+       }
+
        /* stats m (list number of times each command has been used, plus bytecount) */
        if (!strcmp(parameters[0],"m"))
        {
@@ -3160,6 +3165,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];
index d979750b5d159825d714074132c7af53115181f5..2ef0b53bc630dca69dc987512f00031929fa94f6 100644 (file)
@@ -2243,8 +2243,10 @@ 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* e = matches_exception(ip);
+       if ((r) && (!e))
        {
                char reason[MAXBUF];
                snprintf(reason,MAXBUF,"Z-Lined: %s",r);
@@ -2375,23 +2377,26 @@ void FullConnectUser(userrec* user)
 
         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;
-        }
+       char* e = matches_exception(match_against);
+       if (!e)
+       {
+               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);
@@ -2967,6 +2972,7 @@ void SetupCommandTable(void)
        createcommand("GLINE",handle_gline,'o',1);
        createcommand("ZLINE",handle_zline,'o',1);
        createcommand("QLINE",handle_qline,'o',1);
+       createcommand("ELINE",handle_eline,'o',1);
        createcommand("SERVER",handle_server,0,0);
 }
 
index 15032b32a6a10621ef064159a27aab4f7f0dfeaf..ce6257a663decff4bd14c9409871747d53cc751f 100644 (file)
@@ -186,6 +186,7 @@ std::vector<KLine> klines;
 std::vector<GLine> glines;
 std::vector<ZLine> zlines;
 std::vector<QLine> qlines;
+std::vector<ELine> elines;
 
 // Reads the default bans from the config file.
 // only a very small number of bans are defined
@@ -222,6 +223,13 @@ void read_xline_defaults()
                add_kline(0,"<Config>",reason,host);
                log(DEBUG,"Read K line (badhost tag): host=%s reason=%s",host,reason);
        }
+       for (int i = 0; i < ConfValueEnum("exception",&config_f); i++)
+       {
+               ConfValue("exception","host",i,host,&config_f);
+               ConfValue("exception","reason",i,reason,&config_f);
+               add_eline(0,"<Config>",reason,host);
+               log(DEBUG,"Read E line (exception tag): host=%s reason=%s",host,reason);
+       }
 }
 
 // adds a g:line
@@ -239,6 +247,21 @@ void add_gline(long duration, char* source, char* reason, char* hostmask)
        glines.push_back(item);
 }
 
+// adds an e:line (exception to bans)
+
+void add_eline(long duration, char* source, char* reason, char* hostmask)
+{
+        del_eline(hostmask);
+        ELine item;
+        item.duration = duration;
+        strlcpy(item.hostmask,hostmask,MAXBUF);
+        strlcpy(item.reason,reason,MAXBUF);
+        strlcpy(item.source,source,MAXBUF);
+        item.n_matches = 0;
+        item.set_time = time(NULL);
+        elines.push_back(item);
+}
+
 // adds a q:line
 
 void add_qline(long duration, char* source, char* reason, char* nickname)
@@ -301,6 +324,21 @@ bool del_gline(char* hostmask)
        return false;
 }
 
+// deletes a e:line, returns true if the line existed and was removed
+
+bool del_eline(char* hostmask)
+{
+        for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
+        {
+                if (!strcasecmp(hostmask,i->hostmask))
+                {
+                        elines.erase(i);
+                        return true;
+                }
+        }
+        return false;
+}
+
 // deletes a q:line, returns true if the line existed and was removed
 
 bool del_qline(char* nickname)
@@ -430,6 +468,21 @@ char* matches_gline(const char* host)
        return NULL;
 }
 
+char* matches_exception(const char* host)
+{
+       char host2[MAXBUF];
+       snprintf(host2,MAXBUF,"*@%s",host);
+        for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
+        {
+                if ((match(host,i->hostmask)) || (match(host2,i->hostmask)))
+                {
+                        return i->reason;
+                }
+        }
+        return NULL;
+}
+
+
 void gline_set_creation_time(char* host, time_t create_time)
 {
        for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
@@ -521,6 +574,17 @@ void expire_lines()
                        }
                }
 
+                for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
+                {
+                        if ((current > (i->duration + i->set_time)) && (i->duration > 0))
+                        {
+                                WriteOpers("Expiring timed E-Line %s (set by %s %d seconds ago)",i->hostmask,i->source,i->duration);
+                                elines.erase(i);
+                                go_again = true;
+                                break;
+                        }
+                }
+
                for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
                {
                        if ((current > (i->duration + i->set_time)) && (i->duration > 0))
@@ -575,6 +639,12 @@ void apply_lines()
                        if (!strcasecmp(u->second->server,ServerName))
                        {
                                snprintf(host,MAXBUF,"%s@%s",u->second->ident,u->second->host);
+                               if (elines.size())
+                               {
+                                       // ignore people matching exempts
+                                       if (matches_exception(host))
+                                               continue;
+                               }
                                if (glines.size())
                                {
                                        char* check = matches_gline(host);
@@ -660,5 +730,10 @@ void stats_z(userrec* user)
        }
 }
 
-
-
+void stats_e(userrec* user)
+{
+        for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
+        {
+                WriteServ(user->fd,"223 %s :%s %d %d %s %s",user->nick,i->hostmask,i->set_time,i->duration,i->source,i->reason);
+        }
+}