3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 #include "acl/forward.h"
51 #define ACL_F_REGEX_CASE 'i'
52 #define ACL_F_NO_LOOKUP 'n'
53 #define ACL_F_STRICT 's'
54 #define ACL_F_END '\0'
58 * Used to hold a list of one-letter flags which can be passed as parameters
59 * to acls (eg '-i', '-n' etc)
64 explicit ACLFlags(const ACLFlag flags
[]) : supported_(flags
), flags_(0) {}
65 ACLFlags() : flags_(0) {}
66 bool supported(const ACLFlag f
) const; ///< True if the given flag supported
67 void makeSet(const ACLFlag f
) { flags_
|= flagToInt(f
); } ///< Set the given flag
68 /// Return true if the given flag is set
69 bool isSet(const ACLFlag f
) const { return flags_
& flagToInt(f
);}
70 /// Parse optional flags given in the form -[A..Z|a..z]
72 const char *flagsStr() const; ///< Convert the flags to a string representation
75 /// Convert a flag to a 64bit unsigned integer.
76 /// The characters from 'A' to 'z' represented by the values from 65 to 122.
77 /// They are 57 different characters which can be fit to the bits of an 64bit
79 uint64_t flagToInt(const ACLFlag f
) const {
80 assert('A' <= f
&& f
<= 'z');
81 return ((uint64_t)1 << (f
- 'A'));
84 std::string supported_
; ///< The supported character flags
85 uint64_t flags_
; ///< The flags which is set
87 static const ACLFlag NoFlags
[1]; ///< An empty flags list
90 /// A configurable condition. A node in the ACL expression tree.
91 /// Can evaluate itself in FilledChecklist context.
92 /// Does not change during evaluation.
98 void *operator new(size_t);
99 void operator delete(void *);
101 static ACL
*Factory(char const *);
102 static void ParseAclLine(ConfigParser
&parser
, ACL
** head
);
103 static void Initialize();
104 static ACL
*FindByName(const char *name
);
107 explicit ACL(const ACLFlag flgs
[]) : cfgline(NULL
), next(NULL
), flags(flgs
) { memset(name
, '\0', sizeof(name
)); }
110 /// sets user-specified ACL name and squid.conf context
111 void context(const char *name
, const char *configuration
);
113 /// Orchestrates matching checklist against the ACL using match(),
114 /// after checking preconditions and while providing debugging.
115 /// Returns true if and only if there was a successful match.
116 /// Updates the checklist state on match, async, and failure.
117 bool matches(ACLChecklist
*checklist
) const;
119 virtual ACL
*clone() const = 0;
121 /// parses node represenation in squid.conf; dies on failures
122 virtual void parse() = 0;
123 virtual char const *typeString() const = 0;
124 virtual bool isProxyAuth() const;
125 virtual SBufList
dump() const = 0;
126 virtual bool empty() const = 0;
127 virtual bool valid() const;
129 int cacheMatchAcl(dlink_list
* cache
, ACLChecklist
*);
130 virtual int matchForCache(ACLChecklist
*checklist
);
132 virtual void prepareForUse() {}
134 char name
[ACL_NAME_SZ
];
136 ACL
*next
; // XXX: remove or at least use refcounting
137 ACLFlags flags
; ///< The list of given ACL flags
138 bool registered
; ///< added to the global list of ACLs via aclRegister()
147 Prototype(ACL
const *, char const *);
149 static bool Registered(char const *);
150 static ACL
*Factory(char const *);
153 ACL
const *prototype
;
154 char const *typeString
;
157 static std::vector
<Prototype
const *> * Registry
;
158 static void *Initialized
;
159 typedef std::vector
<Prototype
const*>::iterator iterator
;
160 typedef std::vector
<Prototype
const*>::const_iterator const_iterator
;
165 /// Matches the actual data in checklist against this ACL.
166 virtual int match(ACLChecklist
*checklist
) = 0; // XXX: missing const
168 /// whether our (i.e. shallow) match() requires checklist to have a request
169 virtual bool requiresRequest() const;
170 /// whether our (i.e. shallow) match() requires checklist to have a reply
171 virtual bool requiresReply() const;
176 // Authorization ACL result states
181 // Authentication ACL result states
182 ACCESS_AUTH_REQUIRED
, // Missing Credentials
186 /// ACL check answer; TODO: Rename to Acl::Answer
190 // not explicit: allow "aclMatchCode to allow_t" conversions (for now)
191 allow_t(const aclMatchCode aCode
): code(aCode
), kind(0) {}
193 allow_t(): code(ACCESS_DUNNO
), kind(0) {}
195 bool operator ==(const aclMatchCode aCode
) const {
196 return code
== aCode
;
199 bool operator !=(const aclMatchCode aCode
) const {
200 return !(*this == aCode
);
203 operator aclMatchCode() const {
207 aclMatchCode code
; ///< ACCESS_* code
208 int kind
; ///< which custom access list verb matched
211 inline std::ostream
&
212 operator <<(std::ostream
&o
, const allow_t a
)
224 case ACCESS_AUTH_REQUIRED
:
225 o
<< "AUTH_REQUIRED";
232 class acl_proxy_auth_match_cache
236 MEMPROXY_CLASS(acl_proxy_auth_match_cache
);
242 MEMPROXY_CLASS_INLINE(acl_proxy_auth_match_cache
);
245 /// XXX: find a way to remove or at least use a refcounted ACL pointer
246 extern const char *AclMatchedName
; /* NULL */
248 #endif /* SQUID_ACL_H */