]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix bug found in <connect> code, <connect:limit> was checked after finding a class...
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 18 May 2008 17:16:55 +0000 (17:16 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 18 May 2008 17:16:55 +0000 (17:16 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9732 e03df62e-2008-0410-955e-edbf42e46eb7

src/users.cpp

index b81cd6d912d2bd6ca3bc8bbdc3833183144f12ae..fd99f12b74df329ec5493d1dc5a25fd36dbe77d8 100644 (file)
@@ -1701,7 +1701,10 @@ ConnectClass* User::SetClass(const std::string &explicit_name)
                {
                        ConnectClass* c = *i;
 
-                       if (explicit_name == c->GetName() && !c->GetDisabled())
+                       if (c->GetDisabled())
+                               continue; // can't possibly match, removed from conf
+
+                       if (explicit_name == c->GetName())
                        {
                                found = c;
                        }
@@ -1713,37 +1716,47 @@ ConnectClass* User::SetClass(const std::string &explicit_name)
                {
                        ConnectClass* c = *i;
 
-                       if (((match(this->GetIPString(),c->GetHost().c_str(),true)) || (match(this->host,c->GetHost().c_str()))))
+                       /* check if host matches.. */
+                       if (((!match(this->GetIPString(),c->GetHost().c_str(),true)) && (!match(this->host,c->GetHost().c_str()))))
                        {
-                               if (c->GetPort())
-                               {
-                                       if (this->GetPort() == c->GetPort() && !c->GetDisabled())
-                                       {
-                                               found = c;
-                                       }
-                                       else
-                                               continue;
-                               }
-                               else
+                               continue;
+                       }
+
+                       /*
+                        * deny change if change will take class over the limit check it HERE, not after we found a matching class,
+                        * because we should attempt to find another class if this one doesn't match us. -- w00t
+                        */
+                       if (c->limit && (c->RefCount + 1 >= c->limit))
+                       {
+                               ServerInstance->Logs->Log("USERS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
+                               continue;
+                       }
+
+                       /* if it's disabled, we can't match this one. */
+                       if (c->GetDisabled())
+                               continue;
+
+                       /* if it requires a port ... */
+                       if (c->GetPort())
+                       {
+                               /* and our port doesn't match, fail. */
+                               if (this->GetPort() != c->GetPort())
                                {
-                                       if (!c->GetDisabled())
-                                               found = c;
+                                       continue;
                                }
                        }
+
+                       /* we match this class, BUT! we must keep checking in case a further class is type deny and also matches us. */
+                       found = c;
                }
        }
 
-       /* ensure we don't fuck things up refcount wise, only remove them from a class if we find a new one :P */
+       /*
+        * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
+        */
        if (found)
        {
-               /* deny change if change will take class over the limit */
-               if (found->limit && (found->RefCount + 1 >= found->limit))
-               {
-                       ServerInstance->Logs->Log("USERS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", found->limit);
-                       return this->MyClass;
-               }
-
-               /* should always be valid, but just in case .. */
+               /* only fiddle with refcounts if they are already in a class .. */
                if (this->MyClass)
                {
                        if (found == this->MyClass) // no point changing this shit :P