Squid Web Cache v8/master
Loading...
Searching...
No Matches
Acl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_SRC_ACL_ACL_H
10#define SQUID_SRC_ACL_ACL_H
11
12#include "acl/forward.h"
13#include "defines.h"
14#include "dlink.h"
15#include "sbuf/SBuf.h"
16
17#include <algorithm>
18#include <optional>
19#include <ostream>
20
21namespace Acl {
22
24using TypeName = const char *;
26using Maker = Node *(*)(TypeName typeName);
28void RegisterMaker(TypeName typeName, Maker maker);
29
34void SetKey(SBuf &keyStorage, const char *keyParameterName, const char *newKey);
35
36} // namespace Acl
37
39typedef enum {
40 // Authorization ACL result states
44
45 // Authentication Acl::Node result states
46 ACCESS_AUTH_REQUIRED, // Missing Credentials
48
51namespace Acl {
52
53class Answer
54{
55public:
56 // TODO: Find a good way to avoid implicit conversion (without explicitly
57 // casting every ACCESS_ argument in implicit constructor calls).
58 Answer(const aclMatchCode aCode, int aKind = 0): code(aCode), kind(aKind) {}
59
60 Answer() = default;
61
62 bool operator ==(const aclMatchCode aCode) const {
63 return code == aCode;
64 }
65
66 bool operator !=(const aclMatchCode aCode) const {
67 return !(*this == aCode);
68 }
69
70 bool operator ==(const Answer &allow) const {
71 return code == allow.code && kind == allow.kind;
72 }
73
74 operator aclMatchCode() const {
75 return code;
76 }
77
82 bool allowed() const { return code == ACCESS_ALLOWED; }
83
88 bool denied() const { return code == ACCESS_DENIED; }
89
91 bool conflicted() const { return !allowed() && !denied(); }
92
94 const SBuf &lastCheckDescription() const;
95
97
99 int kind = 0;
100
102 bool implicit = false;
103
105 std::optional<SBuf> lastCheckedName;
106};
107
108inline std::ostream &
109operator <<(std::ostream &o, const Answer &a)
110{
111 switch (a) {
112 case ACCESS_DENIED:
113 o << "DENIED";
114 break;
115 case ACCESS_ALLOWED:
116 o << "ALLOWED";
117 break;
118 case ACCESS_DUNNO:
119 o << "DUNNO";
120 break;
122 o << "AUTH_REQUIRED";
123 break;
124 }
125 return o;
126}
127
129void DumpNamedAcls(std::ostream &, const char *directiveName, NamedAcls *);
130
132void FreeNamedAcls(NamedAcls **);
133
134} // namespace Acl
135
138{
140
141public:
142 acl_proxy_auth_match_cache(int matchRv, void * aclData) :
143 matchrv(matchRv),
144 acl_data(aclData)
145 {}
146
149 void *acl_data;
150};
151
152#endif /* SQUID_SRC_ACL_ACL_H */
153
Answer()=default
int kind
the matched custom access list verb (or zero)
Definition Acl.h:99
bool denied() const
Definition Acl.h:88
const SBuf & lastCheckDescription() const
describes the ACL that was evaluated last while obtaining this answer (for debugging)
Definition Acl.cc:123
bool operator!=(const aclMatchCode aCode) const
Definition Acl.h:66
bool conflicted() const
whether Squid is uncertain about the allowed() or denied() answer
Definition Acl.h:91
aclMatchCode code
ACCESS_* code.
Definition Acl.h:96
bool operator==(const aclMatchCode aCode) const
Definition Acl.h:62
Answer(const aclMatchCode aCode, int aKind=0)
Definition Acl.h:58
bool allowed() const
Definition Acl.h:82
bool implicit
whether we were computed by the "negate the last explicit action" rule
Definition Acl.h:102
std::optional< SBuf > lastCheckedName
the name of the ACL (if any) that was evaluated last while obtaining this answer
Definition Acl.h:105
Definition SBuf.h:94
acl_proxy_auth_match_cache(int matchRv, void *aclData)
Definition Acl.h:142
MEMPROXY_CLASS(acl_proxy_auth_match_cache)
aclMatchCode
Definition Acl.h:39
@ ACCESS_AUTH_REQUIRED
Definition Acl.h:46
@ ACCESS_DENIED
Definition Acl.h:41
@ ACCESS_ALLOWED
Definition Acl.h:42
@ ACCESS_DUNNO
Definition Acl.h:43
Definition Acl.cc:33
void RegisterMaker(TypeName typeName, Maker maker)
use the given Acl::Node Maker for all ACLs of the named type
Definition Acl.cc:92
void DumpNamedAcls(std::ostream &, const char *directiveName, NamedAcls *)
report the given list of "acl" directives (using squid.conf syntax)
Definition Acl.cc:335
Node *(*)(TypeName typeName) Maker
a "factory" function for making Acl::Node objects (of some Node child type)
Definition Acl.h:26
const char * TypeName
the ACL type name known to admins
Definition Acl.h:24
void SetKey(SBuf &keyStorage, const char *keyParameterName, const char *newKey)
Definition Acl.cc:100
std::ostream & operator<<(std::ostream &o, const Answer &a)
Definition Acl.h:109
void FreeNamedAcls(NamedAcls **)
delete the given list of "acl" directives
Definition Acl.cc:346