2 * Copyright (C) 1996-2015 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/UserData.h"
14 #include "ConfigParser.h"
25 ACLUserData::~ACLUserData()
28 names
->destroy(xRefFree
);
34 splaystrcasecmp (char * const &l
, char * const &r
)
36 return strcasecmp ((char *)l
,(char *)r
);
40 splaystrcmp (char * const &l
, char * const &r
)
42 return strcmp ((char *)l
,(char *)r
);
46 ACLUserData::match(char const *user
)
48 debugs(28, 7, "aclMatchUser: user is " << user
<< ", case_insensitive is " << flags
.case_insensitive
);
50 if (user
== NULL
|| strcmp(user
, "-") == 0)
54 debugs(28, 7, "aclMatchUser: user REQUIRED and auth-info present.");
60 if (flags
.case_insensitive
)
61 result
= names
->find(const_cast<char *>(user
), splaystrcasecmp
);
63 result
= names
->find(const_cast<char *>(user
), splaystrcmp
);
65 /* Top=splay_splay(user,Top,(splayNode::SPLAYCMP *)dumping_strcmp); */
66 debugs(28, 7, "aclMatchUser: returning " << (result
!= NULL
));
68 return (result
!= NULL
);
71 struct UserDataAclDumpVisitor
{
73 void operator() (char * const & node_data
) {
74 contents
.push_back(SBuf(node_data
));
79 ACLUserData::dump() const
84 sl
.push_back(SBuf("REQUIRED"));
88 if (flags
.case_insensitive
)
89 sl
.push_back(SBuf("-i"));
91 /* damn this is VERY inefficient for long ACL lists... filling
92 * a SBufList this way costs Sum(1,N) iterations. For instance
93 * a 1000-elements list will be filled in 499500 iterations.
96 UserDataAclDumpVisitor visitor
;
97 names
->visit(visitor
);
98 sl
.splice(sl
.end(),visitor
.contents
);
107 debugs(28, 2, "aclParseUserList: parsing user list");
110 names
= new Splay
<char *>();
113 if ((t
= ConfigParser::strtokFile())) {
114 debugs(28, 5, "aclParseUserList: First token is " << t
);
116 if (strcmp("-i", t
) == 0) {
117 debugs(28, 5, "aclParseUserList: Going case-insensitive");
118 flags
.case_insensitive
= true;
119 } else if (strcmp("REQUIRED", t
) == 0) {
120 debugs(28, 5, "aclParseUserList: REQUIRED-type enabled");
121 flags
.required
= true;
123 if (flags
.case_insensitive
)
126 names
->insert(xstrdup(t
), splaystrcmp
);
130 debugs(28, 3, "aclParseUserList: Case-insensitive-switch is " << flags
.case_insensitive
);
131 /* we might inherit from a previous declaration */
133 debugs(28, 4, "aclParseUserList: parsing user list");
135 while ((t
= ConfigParser::strtokFile())) {
136 debugs(28, 6, "aclParseUserList: Got token: " << t
);
138 if (flags
.case_insensitive
)
141 names
->insert(xstrdup(t
), splaystrcmp
);
146 ACLUserData::empty() const
148 return (!names
|| names
->empty()) && !flags
.required
;
151 ACLData
<char const *> *
152 ACLUserData::clone() const
154 /* Splay trees don't clone yet. */
156 return new ACLUserData
;