]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/SourceDomain.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / SourceDomain.cc
1 /*
2 * Copyright (C) 1996-2014 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 /* DEBUG: section 28 Access Control */
10
11 #include "squid.h"
12 #include "acl/Checklist.h"
13 #include "acl/DomainData.h"
14 #include "acl/RegexData.h"
15 #include "acl/SourceDomain.h"
16 #include "fqdncache.h"
17 #include "HttpRequest.h"
18
19 SourceDomainLookup SourceDomainLookup::instance_;
20
21 SourceDomainLookup *
22 SourceDomainLookup::Instance()
23 {
24 return &instance_;
25 }
26
27 void
28 SourceDomainLookup::checkForAsync(ACLChecklist *checklist) const
29 {
30 fqdncache_nbgethostbyaddr(Filled(checklist)->src_addr, LookupDone, checklist);
31 }
32
33 void
34 SourceDomainLookup::LookupDone(const char *fqdn, const DnsLookupDetails &details, void *data)
35 {
36 ACLFilledChecklist *checklist = Filled((ACLChecklist*)data);
37 checklist->markSourceDomainChecked();
38 checklist->request->recordLookup(details);
39 checklist->resumeNonBlockingCheck(SourceDomainLookup::Instance());
40 }
41
42 int
43 ACLSourceDomainStrategy::match (ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &)
44 {
45 const char *fqdn = NULL;
46 fqdn = fqdncache_gethostbyaddr(checklist->src_addr, FQDN_LOOKUP_IF_MISS);
47
48 if (fqdn) {
49 return data->match(fqdn);
50 } else if (!checklist->sourceDomainChecked()) {
51 /* FIXME: Using AclMatchedName here is not OO correct. Should find a way to the current acl */
52 debugs(28, 3, "aclMatchAcl: Can't yet compare '" << AclMatchedName << "' ACL for '" << checklist->src_addr << "'");
53 if (checklist->goAsync(SourceDomainLookup::Instance()))
54 return -1;
55 // else fall through to "none" match, hiding the lookup failure (XXX)
56 }
57
58 return data->match("none");
59 }
60
61 ACLSourceDomainStrategy *
62 ACLSourceDomainStrategy::Instance()
63 {
64 return &Instance_;
65 }
66
67 ACLSourceDomainStrategy ACLSourceDomainStrategy::Instance_;
68