]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Add m_gecosban, implements extban +b r: - hostname bans.
[user/henk/code/inspircd.git] / src / channels.cpp
index d917edb84b6bfd03f4a301594ba56ccd19091eb2..e9d7f4a272339e3920c386540d96163cf4354488 100644 (file)
@@ -451,18 +451,15 @@ bool Channel::IsBanned(User* user)
        return false;
 }
 
-bool Channel::IsExtBanned(User *user, char type)
+bool Channel::IsExtBanned(const std::string &str, char type)
 {
-       char mask[MAXBUF];
        int MOD_RESULT = 0;
-       FOREACH_RESULT(I_OnCheckExtBan,OnCheckExtBan(user, this, type));
+       FOREACH_RESULT(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type));
 
        if (MOD_RESULT == -1)
                return true;
        else if (MOD_RESULT == 0)
        {
-               snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
-
                for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
                {
                        if (i->data[0] != type || i->data[1] != ':')
@@ -471,20 +468,40 @@ bool Channel::IsExtBanned(User *user, char type)
                        // Iterate past char and : to get to the mask without doing a data copy(!)
                        std::string maskptr = i->data.substr(2);
 
-                       /* This allows CIDR ban matching
-                        *
-                        *        Full masked host                             Full unmasked host                     IP with/without CIDR
-                       */
-                       if ((match(user->GetFullHost(), maskptr)) || (match(user->GetFullRealHost(), maskptr)) || (match(mask, maskptr, true)))
-                       {
+                       if (match(str, maskptr))
                                return true;
-                       }
                }
        }
 
        return false;
 }
 
+bool Channel::IsExtBanned(User *user, char type)
+{
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type));
+
+       if (MOD_RESULT == -1)
+               return true;
+       else if (MOD_RESULT == 0)
+       {
+               char mask[MAXBUF];
+               snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
+
+               // XXX: we should probably hook cloaked hosts in here somehow too..
+               if (this->IsExtBanned(mask, type))
+                       return true;
+
+               if (this->IsExtBanned(user->GetFullHost(), type))
+                       return true;
+
+               if (this->IsExtBanned(user->GetFullRealHost(), type))
+                       return true;
+       }
+
+       return false;
+}
+
 /* Channel::PartUser
  * remove a channel from a users record, and return the number of users left.
  * Therefore, if this function returns 0 the caller should delete the Channel.