2 * DEBUG: section 28 Access Control
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
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.
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.
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.
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.
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 #include "acl/DestinationDomain.h"
37 #include "acl/Checklist.h"
38 #include "acl/RegexData.h"
39 #include "acl/DomainData.h"
40 #include "fqdncache.h"
41 #include "HttpRequest.h"
44 DestinationDomainLookup
DestinationDomainLookup::instance_
;
46 DestinationDomainLookup
*
47 DestinationDomainLookup::Instance()
53 DestinationDomainLookup::checkForAsync(ACLChecklist
*cl
) const
55 ACLFilledChecklist
*checklist
= Filled(cl
);
56 checklist
->asyncInProgress(true);
57 fqdncache_nbgethostbyaddr(checklist
->dst_addr
, LookupDone
, checklist
);
61 DestinationDomainLookup::LookupDone(const char *fqdn
, const DnsLookupDetails
&details
, void *data
)
63 ACLFilledChecklist
*checklist
= Filled((ACLChecklist
*)data
);
64 assert (checklist
->asyncState() == DestinationDomainLookup::Instance());
66 checklist
->asyncInProgress(false);
67 checklist
->changeState (ACLChecklist::NullState::Instance());
68 checklist
->markDestinationDomainChecked();
69 checklist
->request
->recordLookup(details
);
70 checklist
->matchNonBlocking();
74 ACLDestinationDomainStrategy::match (ACLData
<MatchType
> * &data
, ACLFilledChecklist
*checklist
)
76 assert(checklist
!= NULL
&& checklist
->request
!= NULL
);
78 if (data
->match(checklist
->request
->GetHost())) {
82 /* numeric IPA? no, trust the above result. */
83 if (checklist
->request
->GetHostIsNumeric() == 0) {
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
);
93 /* raw IP without rDNS? look it up and wait for the result */
94 const ipcache_addrs
*ia
= ipcacheCheckNumeric(checklist
->request
->GetHost());
97 checklist
->dst_rdns
= xstrdup("invalid");
101 checklist
->dst_addr
= ia
->in_addrs
[0];
102 const char *fqdn
= fqdncache_gethostbyaddr(checklist
->dst_addr
, FQDN_LOOKUP_IF_MISS
);
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 checklist
->changeState(DestinationDomainLookup::Instance());
114 return data
->match("none");
117 ACLDestinationDomainStrategy
*
118 ACLDestinationDomainStrategy::Instance()
123 ACLDestinationDomainStrategy
ACLDestinationDomainStrategy::Instance_
;