#include <algorithm>
#include <map>
-const char *AclMatchedName = nullptr;
-
namespace Acl {
/// Acl::Node type name comparison functor
Here());
}
+const SBuf &
+Acl::Answer::lastCheckDescription() const
+{
+ static const auto none = new SBuf("[no-ACL]");
+ // no value_or() because it would create a new SBuf object here
+ return lastCheckedName ? *lastCheckedName : *none;
+}
+
/* Acl::ParsingContext */
ScopedId
fatal ("unusable Acl::Node::delete");
}
-Acl::Node *
-Acl::Node::FindByName(const char *name)
+/// implements both Acl::Node::FindByName() variations
+template <typename SBufOrCString>
+static Acl::Node *
+FindByNameT(const SBufOrCString name)
{
- debugs(28, 9, "name=" << name);
-
- for (auto *a = Config.aclList; a; a = a->next)
- if (!strcasecmp(a->name, name))
+ for (auto a = Config.aclList; a; a = a->next) {
+ if (a->name.caseCmp(name) == 0) {
+ debugs(28, 8, "found " << a->name);
return a;
+ }
+ }
- debugs(28, 9, "found no match");
-
+ debugs(28, 8, "cannot find " << name);
return nullptr;
}
+Acl::Node *
+Acl::Node::FindByName(const SBuf &name)
+{
+ return FindByNameT(name);
+}
+
+Acl::Node *
+Acl::Node::FindByName(const char *name)
+{
+ return FindByNameT(name);
+}
+
Acl::Node::Node() :
cfgline(nullptr),
next(nullptr),
registered(false)
-{
- *name = 0;
-}
+{}
bool
Acl::Node::valid() const
{
debugs(28, 5, "checking " << name);
- // XXX: AclMatchedName does not contain a matched ACL name when the acl
- // does not match. It contains the last (usually leaf) ACL name checked
- // (or is NULL if no ACLs were checked).
- AclMatchedName = name;
+ checklist->setLastCheckedName(name);
int result = 0;
if (!checklist->hasAle() && requiresAle()) {
}
void
-Acl::Node::context(const char *aName, const char *aCfgLine)
+Acl::Node::context(const SBuf &aName, const char *aCfgLine)
{
- name[0] = '\0';
- if (aName)
- xstrncpy(name, aName, ACL_NAME_SZ-1);
+ name = aName;
safe_free(cfgline);
if (aCfgLine)
cfgline = xstrdup(aCfgLine);
return;
}
- if (strlen(t) >= ACL_NAME_SZ) {
- debugs(28, DBG_CRITICAL, "aclParseAclLine: aclParseAclLine: ACL name '" << t <<
- "' too long, max " << ACL_NAME_SZ - 1 << " characters supported");
- parser.destruct();
- return;
- }
-
SBuf aclname(t);
CallParser(ParsingContext::Pointer::Make(aclname), [&] {
- ParseNamed(parser, head, aclname.c_str()); // TODO: Convert Node::name to SBuf
+ ParseNamed(parser, head, aclname);
});
}
/// parses acl directive parts that follow aclname
void
-Acl::Node::ParseNamed(ConfigParser &parser, Node ** const head, const char * const aclname)
+Acl::Node::ParseNamed(ConfigParser &parser, Node ** const head, const SBuf &aclname)
{
/* snarf the ACL type */
const char *theType;
}
theType = "localport";
debugs(28, DBG_IMPORTANT, "WARNING: UPGRADE: ACL 'myport' type has been renamed to 'localport' and matches the port the client connected to.");
- } else if (strcmp(theType, "proto") == 0 && strcmp(aclname, "manager") == 0) {
+ } else if (strcmp(theType, "proto") == 0 && aclname.cmp("manager") == 0) {
// ACL manager is now a built-in and has a different type.
debugs(28, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: UPGRADE: ACL 'manager' is now a built-in ACL. Remove it from your config file.");
return; // ignore the line
{
debugs(28, 3, "freeing ACL " << name);
safe_free(cfgline);
- AclMatchedName = nullptr; // in case it was pointing to our name
}
void