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
);
36 splaystrcasecmp (T
&l
, T
&r
)
38 return strcasecmp ((char *)l
,(char *)r
);
43 splaystrcmp (T
&l
, T
&r
)
45 return strcmp ((char *)l
,(char *)r
);
48 /* general compare functions, these are used for tree search algorithms
49 * so they return <0, 0 or >0 */
51 /* compare a host and a domain */
54 aclHostDomainCompare( char *const &a
, char * const &b
)
56 const char *h
= static_cast<const char *>(a
);
57 const char *d
= static_cast<const char *>(b
);
58 return matchDomainName(h
, d
);
61 /* compare two domains */
65 aclDomainCompare(T
const &a
, T
const &b
)
67 char * const d1
= static_cast<char *>(b
);
68 char * const d2
= static_cast<char *>(a
);
70 ret
= aclHostDomainCompare(d1
, d2
);
75 ret
= aclHostDomainCompare(d3
, d4
);
77 // When a.example.com comes after .example.com in an ACL
78 // sub-domain is ignored. That is okay. Just important
79 bool d3big
= (strlen(d3
) > strlen(d4
)); // Always suggest removing the longer one.
80 debugs(28, DBG_IMPORTANT
, "WARNING: '" << (d3big
?d3
:d4
) << "' is a subdomain of '" << (d3big
?d4
:d3
) << "'");
81 debugs(28, DBG_IMPORTANT
, "WARNING: You should remove '" << (d3big
?d3
:d4
) << "' from the ACL named '" << AclMatchedName
<< "'");
82 debugs(28, 2, HERE
<< "Ignore '" << d3
<< "' to keep splay tree searching predictable");
84 } else if (ret
== 0) {
85 // It may be an exact duplicate. No problem. Just drop.
86 if (strcmp(d1
,d2
)==0) {
87 debugs(28, 2, "WARNING: '" << d2
<< "' is duplicated in the list.");
88 debugs(28, 2, "WARNING: You should remove one '" << d2
<< "' from the ACL named '" << AclMatchedName
<< "'");
91 // When a.example.com comes before .example.com in an ACL
92 // discarding the wildcard is critically bad.
93 // or Maybe even both are wildcards. Things are very weird in those cases.
94 bool d1big
= (strlen(d1
) > strlen(d2
)); // Always suggest removing the longer one.
95 debugs(28, DBG_CRITICAL
, "ERROR: '" << (d1big
?d1
:d2
) << "' is a subdomain of '" << (d1big
?d2
:d1
) << "'");
96 debugs(28, DBG_CRITICAL
, "ERROR: You need to remove '" << (d1big
?d1
:d2
) << "' from the ACL named '" << AclMatchedName
<< "'");
104 ACLDomainData::match(char const *host
)
109 debugs(28, 3, "aclMatchDomainList: checking '" << host
<< "'");
111 char *h
= const_cast<char *>(host
);
112 char const * const * result
= domains
->find(h
, aclHostDomainCompare
);
114 debugs(28, 3, "aclMatchDomainList: '" << host
<< "' " << (result
? "found" : "NOT found"));
116 return (result
!= NULL
);
119 struct AclDomainDataDumpVisitor
{
121 void operator() (char * const & node_data
) {
122 contents
.push_back(SBuf(node_data
));
127 ACLDomainData::dump() const
129 AclDomainDataDumpVisitor visitor
;
130 domains
->visit(visitor
);
131 return visitor
.contents
;
135 ACLDomainData::parse()
140 domains
= new Splay
<char *>();
142 while ((t
= strtokFile())) {
144 domains
->insert(xstrdup(t
), aclDomainCompare
);
149 ACLDomainData::empty() const
151 return domains
->empty();
154 ACLData
<char const *> *
155 ACLDomainData::clone() const
157 /* Splay trees don't clone yet. */
159 return new ACLDomainData
;