]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/acl/Gadgets.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / acl / Gadgets.cc
index 9d39813aac01d003c11766037b42daab4cb2ed72..605d409d7a8d8603cc5aa401cc7547d98d5bdb07 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
 #include "squid.h"
 #include "acl/Acl.h"
 #include "acl/AclDenyInfoList.h"
-#include "acl/AclNameList.h"
 #include "acl/Checklist.h"
 #include "acl/Gadgets.h"
 #include "acl/Strategised.h"
 #include "acl/Tree.h"
+#include "cache_cf.h"
 #include "ConfigParser.h"
 #include "errorpage.h"
 #include "globals.h"
 #include "HttpRequest.h"
+#include "src/sbuf/Stream.h"
 
 #include <set>
 #include <algorithm>
@@ -45,24 +46,21 @@ aclGetDenyInfoPage(AclDenyInfoList ** head, const char *name, int redirect_allow
         return ERR_NONE;
     }
 
-    AclDenyInfoList *A = NULL;
+    AclDenyInfoList *A = nullptr;
 
-    debugs(28, 8, HERE << "got called for " << name);
+    debugs(28, 8, "got called for " << name);
 
     for (A = *head; A; A = A->next) {
-        AclNameList *L = NULL;
-
         if (!redirect_allowed && strchr(A->err_page_name, ':') ) {
-            debugs(28, 8, HERE << "Skip '" << A->err_page_name << "' 30x redirects not allowed as response here.");
+            debugs(28, 8, "Skip '" << A->err_page_name << "' 30x redirects not allowed as response here.");
             continue;
         }
 
-        for (L = A->acl_list; L; L = L->next) {
-            if (!strcmp(name, L->name)) {
-                debugs(28, 8, HERE << "match on " << name);
+        for (const auto &aclName: A->acl_list) {
+            if (aclName.cmp(name) == 0) {
+                debugs(28, 8, "match on " << name);
                 return A->err_page_id;
             }
-
         }
     }
 
@@ -104,39 +102,29 @@ aclIsProxyAuth(const char *name)
 void
 aclParseDenyInfoLine(AclDenyInfoList ** head)
 {
-    char *t = NULL;
-    AclDenyInfoList *A = NULL;
-    AclDenyInfoList *B = NULL;
-    AclDenyInfoList **T = NULL;
-    AclNameList *L = NULL;
-    AclNameList **Tail = NULL;
+    char *t = nullptr;
+    AclDenyInfoList *B;
+    AclDenyInfoList **T;
 
     /* first expect a page name */
 
-    if ((t = ConfigParser::NextToken()) == NULL) {
+    if ((t = ConfigParser::NextToken()) == nullptr) {
         debugs(28, DBG_CRITICAL, "aclParseDenyInfoLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
-        debugs(28, DBG_CRITICAL, "aclParseDenyInfoLine: missing 'error page' parameter.");
+        debugs(28, DBG_CRITICAL, "ERROR: aclParseDenyInfoLine: missing 'error page' parameter.");
         return;
     }
 
-    A = (AclDenyInfoList *)memAllocate(MEM_ACL_DENY_INFO_LIST);
-    A->err_page_id = errorReservePageId(t);
-    A->err_page_name = xstrdup(t);
-    A->next = (AclDenyInfoList *) NULL;
-    /* next expect a list of ACL names */
-    Tail = &A->acl_list;
+    const auto A = new AclDenyInfoList(t, ConfigParser::CurrentLocation());
 
+    /* next expect a list of ACL names */
     while ((t = ConfigParser::NextToken())) {
-        L = (AclNameList *)memAllocate(MEM_ACL_NAME_LIST);
-        xstrncpy(L->name, t, ACL_NAME_SZ-1);
-        *Tail = L;
-        Tail = &L->next;
+        A->acl_list.emplace_back(t);
     }
 
-    if (A->acl_list == NULL) {
+    if (A->acl_list.empty()) {
         debugs(28, DBG_CRITICAL, "aclParseDenyInfoLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
         debugs(28, DBG_CRITICAL, "aclParseDenyInfoLine: deny_info line contains no ACL's, skipping");
-        memFree(A, MEM_ACL_DENY_INFO_LIST);
+        delete A;
         return;
     }
 
@@ -154,15 +142,15 @@ aclParseAccessLine(const char *directive, ConfigParser &, acl_access **treep)
 
     if (!t) {
         debugs(28, DBG_CRITICAL, "aclParseAccessLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
-        debugs(28, DBG_CRITICAL, "aclParseAccessLine: missing 'allow' or 'deny'.");
+        debugs(28, DBG_CRITICAL, "ERROR: aclParseAccessLine: missing 'allow' or 'deny'.");
         return;
     }
 
-    allow_t action = ACCESS_DUNNO;
+    auto action = Acl::Answer(ACCESS_DUNNO);
     if (!strcmp(t, "allow"))
-        action = ACCESS_ALLOWED;
+        action = Acl::Answer(ACCESS_ALLOWED);
     else if (!strcmp(t, "deny"))
-        action = ACCESS_DENIED;
+        action = Acl::Answer(ACCESS_DENIED);
     else {
         debugs(28, DBG_CRITICAL, "aclParseAccessLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
         debugs(28, DBG_CRITICAL, "aclParseAccessLine: expecting 'allow' or 'deny', got '" << t << "'.");
@@ -199,10 +187,10 @@ aclParseAccessLine(const char *directive, ConfigParser &, acl_access **treep)
 }
 
 // aclParseAclList does not expect or set actions (cf. aclParseAccessLine)
-void
+size_t
 aclParseAclList(ConfigParser &, Acl::Tree **treep, const char *label)
 {
-    // accomodate callers unable to convert their ACL list context to string
+    // accommodate callers unable to convert their ACL list context to string
     if (!label)
         label = "...";
 
@@ -213,7 +201,7 @@ aclParseAclList(ConfigParser &, Acl::Tree **treep, const char *label)
 
     Acl::AndNode *rule = new Acl::AndNode;
     rule->context(ctxLine.content(), config_input_line);
-    rule->lineParse();
+    const auto aclCount = rule->lineParse();
 
     MemBuf ctxTree;
     ctxTree.init();
@@ -228,6 +216,8 @@ aclParseAclList(ConfigParser &, Acl::Tree **treep, const char *label)
     assert(treep);
     assert(!*treep);
     *treep = tree;
+
+    return aclCount;
 }
 
 void
@@ -261,7 +251,7 @@ aclDeregister(ACL *acl)
 void
 aclDestroyAcls(ACL ** head)
 {
-    *head = NULL; // Config.aclList
+    *head = nullptr; // Config.aclList
     if (AclSet *acls = RegisteredAcls) {
         debugs(28, 8, "deleting all " << acls->size() << " ACLs");
         while (!acls->empty()) {
@@ -282,7 +272,7 @@ aclDestroyAclList(ACLList **list)
     debugs(28, 8, "aclDestroyAclList: invoked");
     assert(list);
     delete *list;
-    *list = NULL;
+    *list = nullptr;
 }
 
 void
@@ -292,7 +282,7 @@ aclDestroyAccessList(acl_access ** list)
     if (*list)
         debugs(28, 3, "destroying: " << *list << ' ' << (*list)->name);
     delete *list;
-    *list = NULL;
+    *list = nullptr;
 }
 
 /* maex@space.net (06.09.1996)
@@ -301,24 +291,16 @@ aclDestroyAccessList(acl_access ** list)
 void
 aclDestroyDenyInfoList(AclDenyInfoList ** list)
 {
-    AclDenyInfoList *a = NULL;
-    AclDenyInfoList *a_next = NULL;
-    AclNameList *l = NULL;
-    AclNameList *l_next = NULL;
+    AclDenyInfoList *a = nullptr;
+    AclDenyInfoList *a_next = nullptr;
 
     debugs(28, 8, "aclDestroyDenyInfoList: invoked");
 
     for (a = *list; a; a = a_next) {
-        for (l = a->acl_list; l; l = l_next) {
-            l_next = l->next;
-            safe_free(l);
-        }
-
         a_next = a->next;
-        xfree(a->err_page_name);
-        memFree(a, MEM_ACL_DENY_INFO_LIST);
+        delete a;
     }
 
-    *list = NULL;
+    *list = nullptr;
 }