2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 28 Access Control */
12 #include "acl/Checklist.h"
13 #include "acl/DomainData.h"
26 ACLDomainData::~ACLDomainData()
29 domains
->destroy(xRefFree
);
34 splaystrcasecmp (T
&l
, T
&r
)
36 return strcasecmp ((char *)l
,(char *)r
);
41 splaystrcmp (T
&l
, T
&r
)
43 return strcmp ((char *)l
,(char *)r
);
46 /* general compare functions, these are used for tree search algorithms
47 * so they return <0, 0 or >0 */
49 /* compare a host and a domain */
52 aclHostDomainCompare( char *const &a
, char * const &b
)
54 const char *h
= static_cast<const char *>(a
);
55 const char *d
= static_cast<const char *>(b
);
56 return matchDomainName(h
, d
);
59 /* compare two domains */
63 aclDomainCompare(T
const &a
, T
const &b
)
65 char * const d1
= static_cast<char *>(b
);
66 char * const d2
= static_cast<char *>(a
);
68 ret
= aclHostDomainCompare(d1
, d2
);
73 ret
= aclHostDomainCompare(d3
, d4
);
75 // When a.example.com comes after .example.com in an ACL
76 // sub-domain is ignored. That is okay. Just important
77 bool d3big
= (strlen(d3
) > strlen(d4
)); // Always suggest removing the longer one.
78 debugs(28, DBG_IMPORTANT
, "WARNING: '" << (d3big
?d3
:d4
) << "' is a subdomain of '" << (d3big
?d4
:d3
) << "'");
79 debugs(28, DBG_IMPORTANT
, "WARNING: You should remove '" << (d3big
?d3
:d4
) << "' from the ACL named '" << AclMatchedName
<< "'");
80 debugs(28, 2, HERE
<< "Ignore '" << d3
<< "' to keep splay tree searching predictable");
82 } else if (ret
== 0) {
83 // It may be an exact duplicate. No problem. Just drop.
84 if (strcmp(d1
,d2
)==0) {
85 debugs(28, 2, "WARNING: '" << d2
<< "' is duplicated in the list.");
86 debugs(28, 2, "WARNING: You should remove one '" << d2
<< "' from the ACL named '" << AclMatchedName
<< "'");
89 // When a.example.com comes before .example.com in an ACL
90 // discarding the wildcard is critically bad.
91 // or Maybe even both are wildcards. Things are very weird in those cases.
92 bool d1big
= (strlen(d1
) > strlen(d2
)); // Always suggest removing the longer one.
93 debugs(28, DBG_CRITICAL
, "ERROR: '" << (d1big
?d1
:d2
) << "' is a subdomain of '" << (d1big
?d2
:d1
) << "'");
94 debugs(28, DBG_CRITICAL
, "ERROR: You need to remove '" << (d1big
?d1
:d2
) << "' from the ACL named '" << AclMatchedName
<< "'");
102 ACLDomainData::match(char const *host
)
107 debugs(28, 3, "aclMatchDomainList: checking '" << host
<< "'");
109 char *h
= const_cast<char *>(host
);
110 char const * const * result
= domains
->find(h
, aclHostDomainCompare
);
112 debugs(28, 3, "aclMatchDomainList: '" << host
<< "' " << (result
? "found" : "NOT found"));
114 return (result
!= NULL
);
117 struct AclDomainDataDumpVisitor
{
119 void operator() (char * const & node_data
) {
120 contents
.push_back(SBuf(node_data
));
125 ACLDomainData::dump() const
127 AclDomainDataDumpVisitor visitor
;
128 domains
->visit(visitor
);
129 return visitor
.contents
;
133 ACLDomainData::parse()
138 domains
= new Splay
<char *>();
140 while ((t
= strtokFile())) {
142 domains
->insert(xstrdup(t
), aclDomainCompare
);
147 ACLDomainData::empty() const
149 return domains
->empty();
152 ACLData
<char const *> *
153 ACLDomainData::clone() const
155 /* Splay trees don't clone yet. */
157 return new ACLDomainData
;