]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Checklist.cc
4 * DEBUG: section 28 Access Control
5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
37 #include "acl/Checklist.h"
40 ACLChecklist::currentAnswer() const
46 ACLChecklist::currentAnswer(allow_t
const newAnswer
)
57 /** Deny if no rules present. */
58 currentAnswer(ACCESS_DENIED
);
61 checkCallback(currentAnswer());
65 /** The ACL List should NEVER be NULL when calling this method.
66 * Always caller should check for NULL and handle appropriate to its needs first.
67 * We cannot select a sensible default for all callers here. */
68 if (accessList
== NULL
) {
69 debugs(28, DBG_CRITICAL
, "SECURITY ERROR: ACL " << this << " checked with nothing to match against!!");
70 currentAnswer(ACCESS_DENIED
);
71 checkCallback(currentAnswer());
75 /* NOTE: This holds a cbdata reference to the current access_list
76 * entry, not the whole list.
78 while (accessList
!= NULL
) {
80 * If the _acl_access is no longer valid (i.e. its been
81 * freed because of a reconfigure), then bail on this
82 * access check. For now, return ACCESS_DENIED.
85 if (!cbdataReferenceValid(accessList
)) {
86 cbdataReferenceDone(accessList
);
87 debugs(28, 4, "ACLChecklist::check: " << this << " accessList is invalid");
95 if (asyncInProgress()) {
101 * Either the request is allowed, denied, requires authentication.
103 debugs(28, 3, "ACLChecklist::check: " << this << " match found, calling back with " << currentAnswer());
104 cbdataReferenceDone(accessList
); /* A */
105 checkCallback(currentAnswer());
106 /* From here on in, this may be invalid */
111 * Reference the next access entry
113 const acl_access
*A
= accessList
;
117 accessList
= cbdataReference(A
->next
);
119 cbdataReferenceDone(A
);
122 /** If dropped off the end of the list return inversion of last line allow/deny action. */
123 debugs(28, 3, HERE
<< this << " NO match found, returning " <<
124 (currentAnswer() != ACCESS_DENIED
? ACCESS_DENIED
: ACCESS_ALLOWED
));
126 checkCallback(currentAnswer() != ACCESS_DENIED
? ACCESS_DENIED
: ACCESS_ALLOWED
);
130 ACLChecklist::asyncInProgress() const
136 ACLChecklist::asyncInProgress(bool const newAsync
)
138 assert (!finished() && !(asyncInProgress() && newAsync
));
140 debugs(28, 3, "ACLChecklist::asyncInProgress: " << this <<
141 " async set to " << async_
);
145 ACLChecklist::finished() const
151 ACLChecklist::markFinished()
153 assert (!finished() && !asyncInProgress());
155 debugs(28, 3, "ACLChecklist::markFinished: " << this <<
156 " checklist processing finished");
160 ACLChecklist::preCheck()
162 debugs(28, 3, "ACLChecklist::preCheck: " << this << " checking '" << accessList
->cfgline
<< "'");
163 /* what is our result on a match? */
164 currentAnswer(accessList
->allow
);
168 ACLChecklist::checkAccessList()
171 /* does the current AND clause match */
172 matchAclListSlow(accessList
->aclList
);
176 ACLChecklist::checkForAsync()
178 asyncState()->checkForAsync(this);
181 // ACLFilledChecklist overwrites this to unclock something before we
184 ACLChecklist::checkCallback(allow_t answer
)
188 debugs(28, 3, "ACLChecklist::checkCallback: " << this << " answer=" << answer
);
190 callback_
= callback
;
193 if (cbdataReferenceValidDone(callback_data
, &cbdata_
))
194 callback_(answer
, cbdata_
);
200 ACLChecklist::matchAclListSlow(const ACLList
* list
)
202 matchAclList(list
, false);
206 ACLChecklist::matchAclList(const ACLList
* head
, bool const fast
)
208 PROF_start(aclMatchAclList
);
209 const ACLList
*node
= head
;
214 bool nodeMatched
= node
->matches(this);
217 changeState(NullState::Instance());
220 PROF_stop(aclMatchAclList
);
224 if (!nodeMatched
|| state_
!= NullState::Instance()) {
225 debugs(28, 3, "aclmatchAclList: " << this << " returning false (AND list entry failed to match)");
227 bool async
= state_
!= NullState::Instance();
231 bool async_in_progress
= asyncInProgress();
232 debugs(28, 3, "aclmatchAclList: async=" << (async
? 1 : 0) <<
233 " nodeMatched=" << (nodeMatched
? 1 : 0) <<
234 " async_in_progress=" << (async_in_progress
? 1 : 0) <<
235 " lastACLResult() = " << (lastACLResult() ? 1 : 0) <<
236 " finished() = " << finished());
239 PROF_stop(aclMatchAclList
);
243 if (async
&& nodeMatched
&& !asyncInProgress() && lastACLResult()) {
244 // async acl, but using cached response, and it was a match
249 PROF_stop(aclMatchAclList
);
257 debugs(28, 3, "aclmatchAclList: " << this << " returning true (AND list satisfied)");
260 PROF_stop(aclMatchAclList
);
263 ACLChecklist::ACLChecklist() :
266 callback_data (NULL
),
269 allow_(ACCESS_DENIED
),
270 state_(NullState::Instance()),
271 lastACLResult_(false)
275 ACLChecklist::~ACLChecklist()
277 assert (!asyncInProgress());
279 cbdataReferenceDone(accessList
);
281 debugs(28, 4, "ACLChecklist::~ACLChecklist: destroyed " << this);
286 ACLChecklist::AsyncState::changeState (ACLChecklist
*checklist
, AsyncState
*newState
) const
288 checklist
->changeState(newState
);
291 ACLChecklist::NullState
*
292 ACLChecklist::NullState::Instance()
298 ACLChecklist::NullState::checkForAsync(ACLChecklist
*) const
301 ACLChecklist::NullState
ACLChecklist::NullState::_instance
;
304 ACLChecklist::changeState (AsyncState
*newState
)
306 /* only change from null to active and back again,
307 * not active to active.
308 * relax this once conversion to states is complete
311 assert (state_
== NullState::Instance() || newState
== NullState::Instance());
315 ACLChecklist::AsyncState
*
316 ACLChecklist::asyncState() const
322 * Kick off a non-blocking (slow) ACL access list test
324 * NP: this should probably be made Async now.
327 ACLChecklist::nonBlockingCheck(PF
* callback_
, void *callback_data_
)
329 callback
= callback_
;
330 callback_data
= cbdataReference(callback_data_
);
334 /* Warning: do not cbdata lock this here - it
335 * may be static or on the stack
338 ACLChecklist::fastCheck()
340 PROF_start(aclCheckFast
);
341 currentAnswer(ACCESS_DENIED
);
342 debugs(28, 5, "aclCheckFast: list: " << accessList
);
346 matchAclListFast(accessList
->aclList
);
349 PROF_stop(aclCheckFast
);
350 cbdataReferenceDone(accessList
);
351 return currentAnswer() == ACCESS_ALLOWED
;
355 * Reference the next access entry
357 const acl_access
*A
= accessList
;
361 accessList
= cbdataReference(A
->next
);
363 cbdataReferenceDone(A
);
366 debugs(28, 5, "aclCheckFast: no matches, returning: " << (currentAnswer() == ACCESS_DENIED
));
368 PROF_stop(aclCheckFast
);
369 return currentAnswer() == ACCESS_DENIED
;
374 ACLChecklist::checking() const
380 ACLChecklist::checking (bool const newValue
)
382 checking_
= newValue
;
386 ACLChecklist::callerGone()
388 return !cbdataReferenceValid(callback_data
);
392 ACLChecklist::matchAclListFast(const ACLList
* list
)
394 matchAclList(list
, true);