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