]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Summary: ACL tweaks.
authorrobertc <>
Sun, 21 Sep 2003 06:30:46 +0000 (06:30 +0000)
committerrobertc <>
Sun, 21 Sep 2003 06:30:46 +0000 (06:30 +0000)
Keywords:

Move aclCheckFast to ACLChecklist::fastCheck(), and adjust callers.
Move aclChecklistCreate into the ACLChecklist source.
Move the common code leading into matchAclList into the top of matchACLList.

13 files changed:
src/ACLChecklist.cc
src/ACLChecklist.h
src/DelayId.cc
src/HttpHeaderTools.cc
src/acl.cc
src/client_side.cc
src/forward.cc
src/http.cc
src/icp_v2.cc
src/neighbors.cc
src/redirect.cc
src/snmp_core.cc
src/tunnel.cc

index 12ef5fbf3386cdcd27ca48885877cd14eaffddd3..bde58fae93950ae3edc4f4c43584638b50df765d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ACLChecklist.cc,v 1.14 2003/08/04 22:14:38 robertc Exp $
+ * $Id: ACLChecklist.cc,v 1.15 2003/09/21 00:30:48 robertc Exp $
  *
  * DEBUG: section 28    Access Control
  * AUTHOR: Duane Wessels
@@ -194,9 +194,6 @@ ACLChecklist::markFinished()
 void
 ACLChecklist::checkAccessList()
 {
-    debug(28, 3) ("ACLChecklist::checkAccessList: %p checking '%s'\n", this, accessList->cfgline);
-    /* what is our result on a match? */
-    currentAnswer(accessList->allow);
     /* does the current AND clause match */
     matchAclListSlow(accessList->aclList);
 }
@@ -239,6 +236,9 @@ void
 ACLChecklist::matchAclList(const acl_list * head, bool const fast)
 {
     PROF_start(aclMatchAclList);
+    debug(28, 3) ("ACLChecklist::matchAclList: %p checking '%s'\n", this, accessList->cfgline);
+    /* what is our result on a match? */
+    currentAnswer(accessList->allow);
     const acl_list *node = head;
 
     while (node) {
@@ -388,6 +388,33 @@ ACLChecklist::nonBlockingCheck(PF * callback_, void *callback_data_)
     check();
 }
 
+/* Warning: do not cbdata lock this here - it
+ * may be static or on the stack
+ */
+int
+ACLChecklist::fastCheck()
+{
+    PROF_start(aclCheckFast);
+    currentAnswer(ACCESS_DENIED);
+    debug(28, 5) ("aclCheckFast: list: %p\n", accessList);
+
+    while (accessList) {
+        matchAclListFast(accessList->aclList);
+
+        if (finished()) {
+            PROF_stop(aclCheckFast);
+            return currentAnswer() == ACCESS_ALLOWED;
+        }
+
+        accessList = accessList->next;
+    }
+
+    debug(28, 5) ("aclCheckFast: no matches, returning: %d\n", currentAnswer() == ACCESS_DENIED);
+    PROF_stop(aclCheckFast);
+    return currentAnswer() == ACCESS_DENIED;
+}
+
+
 bool
 ACLChecklist::destinationDomainChecked() const
 {
@@ -426,6 +453,50 @@ ACLChecklist::checking (bool const newValue)
     checking_ = newValue;
 }
 
+/*
+ * Any ACLChecklist created by aclChecklistCreate() must eventually be
+ * freed by ACLChecklist::operator delete().  There are two common cases:
+ *
+ * A) Using aclCheckFast():  The caller creates the ACLChecklist using
+ *    aclChecklistCreate(), checks it using aclCheckFast(), and frees it
+ *    using aclChecklistFree().
+ *
+ * B) Using aclNBCheck() and callbacks: The caller creates the
+ *    ACLChecklist using aclChecklistCreate(), and passes it to
+ *    aclNBCheck().  Control eventually passes to ACLChecklist::checkCallback(),
+ *    which will invoke the callback function as requested by the
+ *    original caller of aclNBCheck().  This callback function must
+ *    *not* invoke aclChecklistFree().  After the callback function
+ *    returns, ACLChecklist::checkCallback() will free the ACLChecklist using
+ *    aclChecklistFree().
+ */
+
+ACLChecklist *
+aclChecklistCreate(const acl_access * A, HttpRequest * request, const char *ident)
+{
+    ACLChecklist *checklist = new ACLChecklist;
+
+    if (A)
+        checklist->accessList = cbdataReference(A);
+
+    if (request != NULL) {
+        checklist->request = requestLink(request);
+        checklist->src_addr = request->client_addr;
+        checklist->my_addr = request->my_addr;
+        checklist->my_port = request->my_port;
+    }
+
+#if USE_IDENT
+    if (ident)
+        xstrncpy(checklist->rfc931, ident, USER_IDENT_SZ);
+
+#endif
+
+    checklist->auth_user_request = NULL;
+
+    return checklist;
+}
+
 #ifndef _USE_INLINE_
 #include "ACLChecklist.cci"
 #endif
index fb6ae8b14efca5e68fd09f0e242c8c090901296f..544411e02f91d83cb783aae537f3bef59c838ee9 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ACLChecklist.h,v 1.17 2003/08/11 13:00:41 robertc Exp $
+ * $Id: ACLChecklist.h,v 1.18 2003/09/21 00:30:48 robertc Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -91,6 +91,7 @@ class NullState : public AsyncState
     ACLChecklist &operator=(ACLChecklist const &);
 
     void nonBlockingCheck(PF * callback, void *callback_data);
+    int fastCheck();
     void checkCallback(allow_t answer);
     _SQUID_INLINE_ bool matchAclListFast(const acl_list * list);
     _SQUID_INLINE_ void matchAclListSlow(const acl_list * list);
@@ -154,7 +155,6 @@ private:
 SQUIDCEXTERN ACLChecklist *aclChecklistCreate(const acl_access *,
         HttpRequest *,
         const char *ident);
-SQUIDCEXTERN int aclCheckFast(const acl_access *A, ACLChecklist *);
 
 #ifdef _USE_INLINE_
 #include "ACLChecklist.cci"
index 6f7464471f73742dc72f750f7e4721689fa5b5d1..163aec420e998a9d7858d039e39021910245b87c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: DelayId.cc,v 1.14 2003/09/06 12:47:34 robertc Exp $
+ * $Id: DelayId.cc,v 1.15 2003/09/21 00:30:48 robertc Exp $
  *
  * DEBUG: section 77    Delay Pools
  * AUTHOR: Robert Collins <robertc@squid-cache.org>
@@ -114,8 +114,11 @@ DelayId::DelayClient(clientHttpRequest * http)
 
         ch.request = requestLink(r);
 
+        ch.accessList = DelayPools::delay_data[pool].access;
+
         if (DelayPools::delay_data[pool].theComposite().getRaw() &&
-                aclCheckFast(DelayPools::delay_data[pool].access, &ch)) {
+                ch.fastCheck()) {
+            ch.accessList = NULL;
             DelayId result (pool + 1);
             CompositePoolNode::CompositeSelectionDetails details;
             details.src_addr = ch.src_addr;
@@ -124,6 +127,8 @@ DelayId::DelayClient(clientHttpRequest * http)
             result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
             return result;
         }
+
+        ch.accessList = NULL;
     }
 
 
index 5dc15c8c598c4664d7721ca7239c1b032a2e67cb..920bc47f3846045253238108d844615aa71d6779 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHeaderTools.cc,v 1.44 2003/08/10 11:00:40 robertc Exp $
+ * $Id: HttpHeaderTools.cc,v 1.45 2003/09/21 00:30:46 robertc Exp $
  *
  * DEBUG: section 66    HTTP Header Tools
  * AUTHOR: Alex Rousskov
@@ -515,7 +515,7 @@ httpHdrMangle(HttpHeaderEntry * e, HttpRequest * request)
     hm = &Config.header_access[e->id];
     checklist = aclChecklistCreate(hm->access_list, request, NULL);
 
-    if (1 == aclCheckFast(hm->access_list, checklist)) {
+    if (1 == checklist->fastCheck()) {
         /* aclCheckFast returns 1 for allow. */
         retval = 1;
     } else if (NULL == hm->replacement) {
index 3b80f4b4567f0e7a5f9f2a9e62bc2017d3ab7902..505aebf0c4b5509a76713b2f349fe651b5c59391 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: acl.cc,v 1.311 2003/08/10 11:00:40 robertc Exp $
+ * $Id: acl.cc,v 1.312 2003/09/21 00:30:46 robertc Exp $
  *
  * DEBUG: section 28    Access Control
  * AUTHOR: Duane Wessels
@@ -476,77 +476,6 @@ ACLList::matches (ACLChecklist *checklist) const
     return true;
 }
 
-/* Warning: do not cbdata lock checklist here - it
- * may be static or on the stack
- */
-int
-aclCheckFast(const acl_access * A, ACLChecklist * checklist)
-{
-    allow_t allow = ACCESS_DENIED;
-    PROF_start(aclCheckFast);
-    debug(28, 5) ("aclCheckFast: list: %p\n", A);
-
-    while (A) {
-        allow = A->allow;
-        checklist->matchAclListFast(A->aclList);
-
-        if (checklist->finished()) {
-            PROF_stop(aclCheckFast);
-            return allow == ACCESS_ALLOWED;
-        }
-
-        A = A->next;
-    }
-
-    debug(28, 5) ("aclCheckFast: no matches, returning: %d\n", allow == ACCESS_DENIED);
-    PROF_stop(aclCheckFast);
-    return allow == ACCESS_DENIED;
-}
-
-/*
- * Any ACLChecklist created by aclChecklistCreate() must eventually be
- * freed by ACLChecklist::operator delete().  There are two common cases:
- *
- * A) Using aclCheckFast():  The caller creates the ACLChecklist using
- *    aclChecklistCreate(), checks it using aclCheckFast(), and frees it
- *    using aclChecklistFree().
- *
- * B) Using aclNBCheck() and callbacks: The caller creates the
- *    ACLChecklist using aclChecklistCreate(), and passes it to
- *    aclNBCheck().  Control eventually passes to ACLChecklist::checkCallback(),
- *    which will invoke the callback function as requested by the
- *    original caller of aclNBCheck().  This callback function must
- *    *not* invoke aclChecklistFree().  After the callback function
- *    returns, ACLChecklist::checkCallback() will free the ACLChecklist using
- *    aclChecklistFree().
- */
-
-
-ACLChecklist *
-aclChecklistCreate(const acl_access * A, HttpRequest * request, const char *ident)
-{
-    ACLChecklist *checklist = new ACLChecklist;
-
-    if (A)
-        checklist->accessList = cbdataReference(A);
-
-    if (request != NULL) {
-        checklist->request = requestLink(request);
-        checklist->src_addr = request->client_addr;
-        checklist->my_addr = request->my_addr;
-        checklist->my_port = request->my_port;
-    }
-
-#if USE_IDENT
-    if (ident)
-        xstrncpy(checklist->rfc931, ident, USER_IDENT_SZ);
-
-#endif
-
-    checklist->auth_user_request = NULL;
-
-    return checklist;
-}
 
 /*********************/
 /* Destroy functions */
index f972b1c871f863f617ccddb50839cdaeca695a83..16848fc818d8f0b18a73c838016a21587f2c0c8f 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.659 2003/09/06 12:47:34 robertc Exp $
+ * $Id: client_side.cc,v 1.660 2003/09/21 00:30:46 robertc Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -512,7 +512,7 @@ ClientHttpRequest::logRequest()
 
         checklist->reply = al.reply;
 
-        if (!Config.accessList.log || aclCheckFast(Config.accessList.log, checklist)) {
+        if (!Config.accessList.log || checklist->fastCheck()) {
             al.request = requestLink(request);
             accessLogLog(&al, checklist);
             updateCounters();
@@ -2742,9 +2742,13 @@ httpAccept(int sock, int newfd, ConnectionDetail *details,
 
     identChecklist.my_port = ntohs(details->me.sin_port);
 
-    if (aclCheckFast(Config.accessList.identLookup, &identChecklist))
+    identChecklist.accessList = Config.accessList.identLookup;
+
+    if (identChecklist.fastCheck())
         identStart(&details->me, &details->peer, clientIdentDone, connState);
 
+    identChecklist.accessList = NULL;
+
 #endif
 
     connState->readSomeData();
index 7414826be7629451e9c6a630ccce32cffae2a478..326b3c5d5feb6793c1dcfea9756d336bda5908af 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: forward.cc,v 1.113 2003/09/19 13:25:37 hno Exp $
+ * $Id: forward.cc,v 1.114 2003/09/21 00:30:47 robertc Exp $
  *
  * DEBUG: section 17    Request Forwarding
  * AUTHOR: Duane Wessels
@@ -864,7 +864,9 @@ fwdStart(int fd, StoreEntry * e, HttpRequest * r)
         ch.my_addr = r->my_addr;
         ch.my_port = r->my_port;
         ch.request = requestLink(r);
-        answer = aclCheckFast(Config.accessList.miss, &ch);
+        ch.accessList = Config.accessList.miss;
+        answer = ch.fastCheck();
+        ch.accessList = NULL;
 
         if (answer == 0) {
             err = errorCon(ERR_FORWARDING_DENIED, HTTP_FORBIDDEN);
index 1f88ba08fbfdd1529033fad4e4601bdfb3a753d4..c7612e0974835a84f83a28717bdf677b24f30c80 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: http.cc,v 1.427 2003/09/01 03:49:38 robertc Exp $
+ * $Id: http.cc,v 1.428 2003/09/21 00:30:47 robertc Exp $
  *
  * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
  * AUTHOR: Harvest Derived
@@ -1665,17 +1665,20 @@ httpSendRequestEntityDone(int fd, void *data)
     ACLChecklist ch;
     debug(11, 5) ("httpSendRequestEntityDone: FD %d\n", fd);
     ch.request = requestLink(httpState->request);
+    ch.accessList = Config.accessList.brokenPosts;
 
     if (!Config.accessList.brokenPosts) {
         debug(11, 5) ("httpSendRequestEntityDone: No brokenPosts list\n");
         HttpStateData::SendComplete(fd, NULL, 0, COMM_OK, data);
-    } else if (!aclCheckFast(Config.accessList.brokenPosts, &ch)) {
+    } else if (!ch.fastCheck()) {
         debug(11, 5) ("httpSendRequestEntityDone: didn't match brokenPosts\n");
         HttpStateData::SendComplete(fd, NULL, 0, COMM_OK, data);
     } else {
         debug(11, 2) ("httpSendRequestEntityDone: matched brokenPosts\n");
         comm_old_write(fd, "\r\n", 2, HttpStateData::SendComplete, data, NULL);
     }
+
+    ch.accessList = NULL;
 }
 
 static void
index 8fdbc53e53388d83a8d0ee2edaaad3426054e255..b69255e7042d9ea81bb3288fa8ce0eb58f1b93b5 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: icp_v2.cc,v 1.83 2003/09/01 03:49:39 robertc Exp $
+ * $Id: icp_v2.cc,v 1.84 2003/09/21 00:30:47 robertc Exp $
  *
  * DEBUG: section 12    Internet Cache Protocol
  * AUTHOR: Duane Wessels
@@ -398,7 +398,10 @@ icpAccessAllowed(struct sockaddr_in *from, HttpRequest * icp_request)
     checklist.src_addr = from->sin_addr;
     checklist.my_addr = no_addr;
     checklist.request = requestLink(icp_request);
-    return aclCheckFast(Config.accessList.icp, &checklist);
+    checklist.accessList = Config.accessList.icp;
+    int result = checklist.fastCheck();
+    checklist.accessList = NULL;
+    return result;
 }
 
 char const *
index c3048542b08c705cde940fb766f950690968dcc7..535e066815adab6b9773a98040e1739c05f3380f 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: neighbors.cc,v 1.322 2003/08/13 00:39:16 wessels Exp $
+ * $Id: neighbors.cc,v 1.323 2003/09/21 00:30:47 robertc Exp $
  *
  * DEBUG: section 15    Neighbor Routines
  * AUTHOR: Harvest Derived
@@ -185,6 +185,8 @@ peerAllowedToUse(const peer * p, HttpRequest * request)
 
     checklist.request = requestLink(request);
 
+    checklist.accessList = p->access;
+
 #if 0 && USE_IDENT
     /*
      * this is currently broken because 'request->user_ident' has been
@@ -196,7 +198,11 @@ peerAllowedToUse(const peer * p, HttpRequest * request)
 
 #endif
 
-    return aclCheckFast(p->access, &checklist);
+    int result = checklist.fastCheck();
+
+    checklist.accessList = NULL;
+
+    return result;
 }
 
 /* Return TRUE if it is okay to send an ICP request to this peer.   */
index 6400c8dd4b71e3b1aeda00acd4c6f60776ae0902..c31cf4e788db9e3678df0eb32fe91919d52be4f2 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: redirect.cc,v 1.101 2003/07/14 14:16:02 robertc Exp $
+ * $Id: redirect.cc,v 1.102 2003/09/21 00:30:47 robertc Exp $
  *
  * DEBUG: section 61    Redirector
  * AUTHOR: Duane Wessels
@@ -129,12 +129,16 @@ redirectStart(clientHttpRequest * http, RH * handler, void *data)
         }
 
         ch.request = requestLink(http->request);
+        ch.accessList = Config.accessList.redirector;
 
-        if (!aclCheckFast(Config.accessList.redirector, &ch)) {
+        if (!ch.fastCheck()) {
+            ch.accessList = NULL;
             /* denied -- bypass redirector */
             handler(data, NULL);
             return;
         }
+
+        ch.accessList = NULL;
     }
 
     if (Config.onoff.redirector_bypass && redirectors->stats.queue_size) {
index 6c7ec78f7e64ba3cf58c2eb24eab6f403d039718..b50f5d3a88c41f120cb7288f0c64333288a28d67 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: snmp_core.cc,v 1.64 2003/02/25 12:24:35 robertc Exp $
+ * $Id: snmp_core.cc,v 1.65 2003/09/21 00:30:47 robertc Exp $
  *
  * DEBUG: section 49    SNMP support
  * AUTHOR: Glenn Chisholm
@@ -540,9 +540,12 @@ snmpDecodePacket(snmp_request_t * rq)
     ACLChecklist checklist;
     checklist.src_addr = rq->from.sin_addr;
     checklist.snmp_community = (char *) Community;
+    checklist.accessList = Config.accessList.snmp;
 
     if (Community)
-        allow = aclCheckFast(Config.accessList.snmp, &checklist);
+        allow = checklist.fastCheck();
+
+    checklist.accessList = NULL;
 
     if ((snmp_coexist_V2toV1(PDU)) && (Community) && (allow)) {
         rq->community = Community;
index fc7d060f36ef32d83a71655591adb7ff226ca49c..c1c5901dd741452df3b37e00ba55c19c7fe5e785 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tunnel.cc,v 1.145 2003/08/10 11:00:44 robertc Exp $
+ * $Id: tunnel.cc,v 1.146 2003/09/21 00:30:47 robertc Exp $
  *
  * DEBUG: section 26    Secure Sockets Layer Proxy
  * AUTHOR: Duane Wessels
@@ -561,7 +561,9 @@ sslStart(clientHttpRequest * http, size_t * size_ptr, int *status_ptr)
         ch.my_addr = request->my_addr;
         ch.my_port = request->my_port;
         ch.request = requestLink(request);
-        answer = aclCheckFast(Config.accessList.miss, &ch);
+        ch.accessList = Config.accessList.miss;
+        answer = ch.fastCheck();
+        ch.accessList = NULL;
 
         if (answer == 0) {
             err = errorCon(ERR_FORWARDING_DENIED, HTTP_FORBIDDEN);