]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3980: FATAL ERROR due to max_user_ip -s option
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Tue, 17 Dec 2013 07:12:55 +0000 (00:12 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 17 Dec 2013 07:12:55 +0000 (00:12 -0700)
src/acl/Acl.h
src/auth/AclMaxUserIp.cc
src/auth/AclMaxUserIp.h
src/tests/testACLMaxUserIP.cc

index dc61d568f4207226edbd25842c6b2a7572c10d6b..9e71e397d9825a821de099cb3d190a5b33fa576b 100644 (file)
@@ -53,6 +53,7 @@ typedef char ACLFlag;
 // ACLData Flags
 #define ACL_F_REGEX_CASE 'i'
 #define ACL_F_NO_LOOKUP 'n'
+#define ACL_F_STRICT 's'
 #define ACL_F_END '\0'
 
 /**
index 0a7072dd0427aa3aeaa6453078706fc6b1703efe..e1023d91e04e3921e8b6ea6983f643cf57808413 100644 (file)
 #include "Parsing.h"
 #include "wordlist.h"
 
+ACLFlag
+ACLMaxUserIP::SupportedFlags[] = {ACL_F_STRICT, ACL_F_END};
+
 ACL *
 ACLMaxUserIP::clone() const
 {
     return new ACLMaxUserIP(*this);
 }
 
-ACLMaxUserIP::ACLMaxUserIP (char const *theClass) : class_ (theClass), maximum(0)
+ACLMaxUserIP::ACLMaxUserIP (char const *theClass) : ACL(SupportedFlags), class_ (theClass), maximum(0)
 {}
 
-ACLMaxUserIP::ACLMaxUserIP (ACLMaxUserIP const & old) :class_ (old.class_), maximum (old.maximum), flags (old.flags)
-{}
+ACLMaxUserIP::ACLMaxUserIP (ACLMaxUserIP const & old) : class_ (old.class_), maximum (old.maximum)
+{
+   flags = old.flags;
+}
 
 ACLMaxUserIP::~ACLMaxUserIP()
 {}
@@ -61,15 +66,6 @@ ACLMaxUserIP::parse()
 
     debugs(28, 5, "aclParseUserMaxIP: First token is " << t);
 
-    if (strcmp("-s", t) == 0) {
-        debugs(28, 5, "aclParseUserMaxIP: Going strict");
-        flags.strict = true;
-        t = ConfigParser::strtokFile();
-    }
-
-    if (!t)
-        return;
-
     maximum = xatoi(t);
 
     debugs(28, 5, "aclParseUserMaxIP: Max IP address's " << maximum);
@@ -97,7 +93,7 @@ ACLMaxUserIP::match(Auth::UserRequest::Pointer auth_user_request, Ip::Address co
     debugs(28, DBG_IMPORTANT, "aclMatchUserMaxIP: user '" << auth_user_request->username() << "' tries to use too many IP addresses (max " << maximum << " allowed)!");
 
     /* this is a match */
-    if (flags.strict) {
+    if (flags.isSet(ACL_F_STRICT)) {
         /*
          * simply deny access - the user name is already associated with
          * the request
@@ -154,9 +150,6 @@ ACLMaxUserIP::dump() const
 
     wordlist *W = NULL;
 
-    if (flags.strict)
-        wordlistAdd(&W, "-s");
-
     char buf[128];
 
     snprintf(buf, sizeof(buf), "%lu", (unsigned long int) maximum);
index 5d5e962b1cd29458997e88df1a4d0ebe36f07c09..13414edfe13e15e81d083e4bc9b78da15f5a00f4 100644 (file)
@@ -62,21 +62,16 @@ public:
 
     int getMaximum() const {return maximum;}
 
-    int getStrict() const {return flags.strict;}
+    bool getStrict() const {return flags.isSet(ACL_F_STRICT);}
 
 private:
     static Prototype RegistryProtoype;
     static ACLMaxUserIP RegistryEntry_;
+    static ACLFlag  SupportedFlags[];
 
     int match(Auth::UserRequest::Pointer, Ip::Address const &);
     char const *class_;
     int maximum;
-
-    struct Flags {
-        Flags() : strict(false) {}
-
-        bool strict;
-    } flags;
 };
 
 MEMPROXY_CLASS_INLINE(ACLMaxUserIP);
index d112b3f5b765d0282e5dde6b0e4901a03a9d2132..ed9fe7529cc30e2a759e848d392b629aee3b027b 100644 (file)
@@ -21,25 +21,33 @@ testACLMaxUserIP::testDefaults()
     /* 0 is not a valid maximum, so we start at 0 */
     CPPUNIT_ASSERT_EQUAL(0,anACL.getMaximum());
     /* and we have no option to turn strict OFF, so start ON. */
-    CPPUNIT_ASSERT_EQUAL(0,anACL.getStrict());
+    CPPUNIT_ASSERT_EQUAL(false,anACL.getStrict());
     /* an unparsed acl must not be valid - there is no sane default */
     CPPUNIT_ASSERT_EQUAL(false,anACL.valid());
 }
 
+ACL::Prototype ACLMaxUserIP::RegistryProtoype(&ACLMaxUserIP::RegistryEntry_, "max_user_ip");
+ACLMaxUserIP ACLMaxUserIP::RegistryEntry_("max_user_ip");
+
 void
 testACLMaxUserIP::testParseLine()
 {
     /* a config line to pass with a lead-in token to seed the parser. */
-    char * line = xstrdup("-s 1");
+    char * line = xstrdup("test max_user_ip -s 1");
     /* seed the parser */
     ConfigParser::SetCfgLine(line);
-    ACLMaxUserIP anACL("max_user_ip");
-    anACL.parse();
+    ACL *anACL = NULL;
+    ConfigParser LegacyParser;
+    ACL::ParseAclLine(LegacyParser, &anACL);
+    ACLMaxUserIP *maxUserIpACL = dynamic_cast<ACLMaxUserIP *>(anACL);
+    CPPUNIT_ASSERT(maxUserIpACL);
+
     /* we want a maximum of one, and strict to be true */
-    CPPUNIT_ASSERT_EQUAL(1,anACL.getMaximum());
-    CPPUNIT_ASSERT_EQUAL(1,anACL.getStrict());
+    CPPUNIT_ASSERT_EQUAL(1, maxUserIpACL->getMaximum());
+    CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->getStrict());
     /* the acl must be vaid */
-    CPPUNIT_ASSERT_EQUAL(true,anACL.valid());
+    CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->valid());
+    delete anACL;
     xfree(line);
 }