/*
- * DEBUG: section 28 Access Control
- * AUTHOR: Amos Jeffries
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
*
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- *
- * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* DEBUG: section 28 Access Control */
+
#include "squid.h"
#if USE_SQUID_EUI
#include "acl/Eui64.h"
#include "acl/FilledChecklist.h"
#include "cache_cf.h"
-#include "Debug.h"
+#include "debug/Stream.h"
#include "eui/Eui64.h"
#include "globals.h"
#include "ip/Address.h"
-static void aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist);
-static int aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c);
-static SplayNode<Eui::Eui64 *>::SPLAYCMP aclEui64Compare;
-static SplayNode<Eui::Eui64 *>::SPLAYWALKEE aclDumpEuiListWalkee;
-
-ACL *
-ACLEui64::clone() const
-{
- return new ACLEui64(*this);
-}
-
-ACLEui64::ACLEui64 (char const *theClass) : data (NULL), class_ (theClass)
+ACLEui64::ACLEui64 (char const *theClass) : class_ (theClass)
{}
-ACLEui64::ACLEui64 (ACLEui64 const & old) : data (NULL), class_ (old.class_)
-{
- /* we don't have copy constructors for the data yet */
- assert (!old.data);
-}
-
-ACLEui64::~ACLEui64()
-{
- if (data)
- data->destroy(SplayNode<Eui::Eui64*>::DefaultFree);
-}
-
char const *
ACLEui64::typeString() const
{
bool
ACLEui64::empty () const
{
- return data->empty();
+ return eui64Data.empty();
}
-Eui::Eui64 *
+static Eui::Eui64 *
aclParseEuiData(const char *t)
{
char buf[256];
debugs(28, 5, "aclParseEuiData: " << t);
if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) {
- debugs(28, DBG_CRITICAL, "aclParseEuiData: Bad EUI-64 address: '" << t << "'");
- safe_free(q);
- return NULL;
+ debugs(28, DBG_CRITICAL, "ERROR: aclParseEuiData: Bad EUI-64 address: '" << t << "'");
+ delete q;
+ return nullptr;
}
if (!q->decode(buf)) {
debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
- debugs(28, DBG_CRITICAL, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'");
- safe_free(q);
- return NULL;
+ debugs(28, DBG_CRITICAL, "ERROR: aclParseEuiData: Ignoring invalid EUI-64 acl entry: cannot parse '" << buf << "'");
+ delete q;
+ return nullptr;
}
return q;
void
ACLEui64::parse()
{
- aclParseEuiList(&data);
-}
-
-void
-aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist)
-{
- char *t = NULL;
- SplayNode<Eui::Eui64*> **Top = curlist;
- Eui::Eui64 *q = NULL;
-
- while ((t = strtokFile())) {
- if ((q = aclParseEuiData(t)) == NULL)
- continue;
-
- *Top = (*Top)->insert(q, aclEui64Compare);
+ while (const char * t = ConfigParser::strtokFile()) {
+ if (Eui::Eui64 * q = aclParseEuiData(t)) {
+ eui64Data.insert(*q);
+ delete q;
+ }
}
}
return 0;
}
- return aclMatchEui(&data, checklist->src_addr);
-}
-
-/***************/
-/* aclMatchEui */
-/***************/
-int
-aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c)
-{
- Eui::Eui64 result;
- SplayNode<Eui::Eui64 *> **Top = dataptr;
-
- if (result.lookup(c)) {
- /* Do ACL match lookup */
- *Top = (*Top)->splay(&result, aclEui64Compare);
- debugs(28, 3, "aclMatchEui: '" << c << "' " << (splayLastResult ? "NOT found" : "found"));
- return (0 == splayLastResult);
+ Eui::Eui64 lookingFor;
+ if (lookingFor.lookup(checklist->src_addr)) {
+ bool found = (eui64Data.find(lookingFor) != eui64Data.end());
+ debugs(28, 3, checklist->src_addr << "' " << (found ? "found" : "NOT found"));
+ return found;
}
- /*
- * Address was not found on any interface
- */
- debugs(28, 3, "aclMatchEui: " << c << " NOT found");
+ debugs(28, 3, checklist->src_addr << " NOT found");
return 0;
}
-static int
-aclEui64Compare(Eui::Eui64 * const &a, Eui::Eui64 * const &b)
-{
- return memcmp(a, b, sizeof(Eui::Eui64));
-}
-
-static void
-aclDumpEuiListWalkee(Eui::Eui64 * const &node, void *state)
-{
- static char buf[48];
- node->encode(buf, 48);
- static_cast<SBufList *>(state)->push_back(SBuf(buf));
-}
-
SBufList
ACLEui64::dump() const
{
- SBufList w;
- data->walk(aclDumpEuiListWalkee, &w);
- return w;
+ SBufList sl;
+ for (auto i = eui64Data.begin(); i != eui64Data.end(); ++i) {
+ static char buf[48];
+ i->encode(buf,48);
+ sl.push_back(SBuf(buf));
+ }
+ return sl;
}
#endif /* USE_SQUID_EUI */
+