]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/DestinationDomain.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / DestinationDomain.cc
1 /*
2 * DEBUG: section 28 Access Control
3 * AUTHOR: Duane Wessels
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 *
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
33 */
34
35 #include "squid.h"
36 #include "acl/Checklist.h"
37 #include "acl/DestinationDomain.h"
38 #include "acl/DomainData.h"
39 #include "acl/RegexData.h"
40 #include "fqdncache.h"
41 #include "HttpRequest.h"
42 #include "ipcache.h"
43
44 DestinationDomainLookup DestinationDomainLookup::instance_;
45
46 DestinationDomainLookup *
47 DestinationDomainLookup::Instance()
48 {
49 return &instance_;
50 }
51
52 void
53 DestinationDomainLookup::checkForAsync(ACLChecklist *cl) const
54 {
55 ACLFilledChecklist *checklist = Filled(cl);
56 fqdncache_nbgethostbyaddr(checklist->dst_addr, LookupDone, checklist);
57 }
58
59 void
60 DestinationDomainLookup::LookupDone(const char *fqdn, const DnsLookupDetails &details, void *data)
61 {
62 ACLFilledChecklist *checklist = Filled((ACLChecklist*)data);
63 checklist->markDestinationDomainChecked();
64 checklist->request->recordLookup(details);
65 checklist->resumeNonBlockingCheck(DestinationDomainLookup::Instance());
66 }
67
68 int
69 ACLDestinationDomainStrategy::match (ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &flags)
70 {
71 assert(checklist != NULL && checklist->request != NULL);
72
73 if (data->match(checklist->request->GetHost())) {
74 return 1;
75 }
76
77 if (flags.isSet(ACL_F_NO_LOOKUP)) {
78 debugs(28, 3, "aclMatchAcl: No-lookup DNS ACL '" << AclMatchedName << "' for '" << checklist->request->GetHost() << "'");
79 return 0;
80 }
81
82 /* numeric IPA? no, trust the above result. */
83 if (checklist->request->GetHostIsNumeric() == 0) {
84 return 0;
85 }
86
87 /* do we already have the rDNS? match on it if we do. */
88 if (checklist->dst_rdns) {
89 debugs(28, 3, "aclMatchAcl: '" << AclMatchedName << "' match with stored rDNS '" << checklist->dst_rdns << "' for '" << checklist->request->GetHost() << "'");
90 return data->match(checklist->dst_rdns);
91 }
92
93 /* raw IP without rDNS? look it up and wait for the result */
94 const ipcache_addrs *ia = ipcacheCheckNumeric(checklist->request->GetHost());
95 if (!ia) {
96 /* not a valid IPA */
97 checklist->dst_rdns = xstrdup("invalid");
98 return 0;
99 }
100
101 checklist->dst_addr = ia->in_addrs[0];
102 const char *fqdn = fqdncache_gethostbyaddr(checklist->dst_addr, FQDN_LOOKUP_IF_MISS);
103
104 if (fqdn) {
105 checklist->dst_rdns = xstrdup(fqdn);
106 return data->match(fqdn);
107 } else if (!checklist->destinationDomainChecked()) {
108 /* FIXME: Using AclMatchedName here is not OO correct. Should find a way to the current acl */
109 debugs(28, 3, "aclMatchAcl: Can't yet compare '" << AclMatchedName << "' ACL for '" << checklist->request->GetHost() << "'");
110 if (checklist->goAsync(DestinationDomainLookup::Instance()))
111 return -1;
112 // else fall through to "none" match, hiding the lookup failure (XXX)
113 }
114
115 return data->match("none");
116 }
117
118 ACLDestinationDomainStrategy *
119 ACLDestinationDomainStrategy::Instance()
120 {
121 return &Instance_;
122 }
123
124 ACLDestinationDomainStrategy ACLDestinationDomainStrategy::Instance_;