Acl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 
21 namespace Acl {
22 
24 using TypeName = const char *;
26 using Maker = Node *(*)(TypeName typeName);
28 void RegisterMaker(TypeName typeName, Maker maker);
29 
34 void SetKey(SBuf &keyStorage, const char *keyParameterName, const char *newKey);
35 
36 } // namespace Acl
37 
39 typedef enum {
40  // Authorization ACL result states
44 
45  // Authentication Acl::Node result states
46  ACCESS_AUTH_REQUIRED, // Missing Credentials
47 } aclMatchCode;
48 
51 namespace Acl {
52 
53 class Answer
54 {
55 public:
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 
108 inline std::ostream &
109 operator <<(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 
129 void DumpNamedAcls(std::ostream &, const char *directiveName, NamedAcls *);
130 
132 void FreeNamedAcls(NamedAcls **);
133 
134 } // namespace Acl
135 
138 {
140 
141 public:
142  acl_proxy_auth_match_cache(int matchRv, void * aclData) :
143  matchrv(matchRv),
144  acl_data(aclData)
145  {}
146 
148  int matchrv;
149  void *acl_data;
150 };
151 
152 #endif /* SQUID_SRC_ACL_ACL_H */
153 
void DumpNamedAcls(std::ostream &, const char *directiveName, NamedAcls *)
report the given list of "acl" directives (using squid.conf syntax)
Definition: Acl.cc:335
void RegisterMaker(TypeName typeName, Maker maker)
use the given Acl::Node Maker for all ACLs of the named type
Definition: Acl.cc:92
const SBuf & lastCheckDescription() const
describes the ACL that was evaluated last while obtaining this answer (for debugging)
Definition: Acl.cc:123
Node *(*)(TypeName typeName) Maker
a "factory" function for making Acl::Node objects (of some Node child type)
Definition: Acl.h:26
Answer()=default
Definition: SBuf.h:93
void FreeNamedAcls(NamedAcls **)
delete the given list of "acl" directives
Definition: Acl.cc:346
Definition: Acl.cc:33
void SetKey(SBuf &keyStorage, const char *keyParameterName, const char *newKey)
Definition: Acl.cc:100
bool implicit
whether we were computed by the "negate the last explicit action" rule
Definition: Acl.h:102
@ ACCESS_AUTH_REQUIRED
Definition: Acl.h:46
MEMPROXY_CLASS(acl_proxy_auth_match_cache)
Answer(const aclMatchCode aCode, int aKind=0)
Definition: Acl.h:58
bool denied() const
Definition: Acl.h:88
aclMatchCode code
ACCESS_* code.
Definition: Acl.h:96
acl_proxy_auth_match_cache(int matchRv, void *aclData)
Definition: Acl.h:142
bool operator==(const aclMatchCode aCode) const
Definition: Acl.h:62
bool allowed() const
Definition: Acl.h:82
Definition: Node.h:25
const char * TypeName
the ACL type name known to admins
Definition: Acl.h:24
@ ACCESS_ALLOWED
Definition: Acl.h:42
@ ACCESS_DENIED
Definition: Acl.h:41
std::optional< SBuf > lastCheckedName
the name of the ACL (if any) that was evaluated last while obtaining this answer
Definition: Acl.h:105
@ ACCESS_DUNNO
Definition: Acl.h:43
int kind
the matched custom access list verb (or zero)
Definition: Acl.h:99
bool conflicted() const
whether Squid is uncertain about the allowed() or denied() answer
Definition: Acl.h:91
bool operator!=(const aclMatchCode aCode) const
Definition: Acl.h:66
aclMatchCode
Definition: Acl.h:39
std::ostream & operator<<(std::ostream &o, const Answer &a)
Definition: Acl.h:109

 

Introduction

Documentation

Support

Miscellaneous