]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/UserData.cc
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/UserData.h"
14 #include "ConfigParser.h"
24 ACLUserData::~ACLUserData()
27 names
->destroy(xRefFree
);
31 splaystrcasecmp (char * const &l
, char * const &r
)
33 return strcasecmp ((char *)l
,(char *)r
);
37 splaystrcmp (char * const &l
, char * const &r
)
39 return strcmp ((char *)l
,(char *)r
);
43 ACLUserData::match(char const *user
)
45 SplayNode
<char *> *Top
= names
;
47 debugs(28, 7, "aclMatchUser: user is " << user
<< ", case_insensitive is " << flags
.case_insensitive
);
48 debugs(28, 8, "Top is " << Top
<< ", Top->data is " << ((char *) (Top
!= NULL
? (Top
)->data
: "Unavailable")));
50 if (user
== NULL
|| strcmp(user
, "-") == 0)
54 debugs(28, 7, "aclMatchUser: user REQUIRED and auth-info present.");
58 if (flags
.case_insensitive
)
59 Top
= Top
->splay((char *)user
, splaystrcasecmp
);
61 Top
= Top
->splay((char *)user
, splaystrcmp
);
63 /* Top=splay_splay(user,Top,(splayNode::SPLAYCMP *)dumping_strcmp); */
64 debugs(28, 7, "aclMatchUser: returning " << !splayLastResult
<< ",Top is " <<
65 Top
<< ", Top->data is " << ((char *) (Top
? Top
->data
: "Unavailable")));
69 return !splayLastResult
;
73 aclDumpUserListWalkee(char * const & node_data
, void *outlist
)
75 /* outlist is really a SBufList* */
76 static_cast<SBufList
*>(outlist
)->push_back(SBuf(node_data
));
80 ACLUserData::dump() const
84 if (flags
.case_insensitive
)
85 sl
.push_back(SBuf("-i"));
87 /* damn this is VERY inefficient for long ACL lists... filling
88 * a SBufList this way costs Sum(1,N) iterations. For instance
89 * a 1000-elements list will be filled in 499500 iterations.
92 sl
.push_back(SBuf("REQUIRED"));
94 names
->walk(aclDumpUserListWalkee
, &sl
);
102 debugs(28, 2, "aclParseUserList: parsing user list");
105 if ((t
= ConfigParser::strtokFile())) {
106 debugs(28, 5, "aclParseUserList: First token is " << t
);
108 if (strcmp("-i", t
) == 0) {
109 debugs(28, 5, "aclParseUserList: Going case-insensitive");
110 flags
.case_insensitive
= true;
111 } else if (strcmp("REQUIRED", t
) == 0) {
112 debugs(28, 5, "aclParseUserList: REQUIRED-type enabled");
113 flags
.required
= true;
115 if (flags
.case_insensitive
)
118 names
= names
->insert(xstrdup(t
), splaystrcmp
);
122 debugs(28, 3, "aclParseUserList: Case-insensitive-switch is " << flags
.case_insensitive
);
123 /* we might inherit from a previous declaration */
125 debugs(28, 4, "aclParseUserList: parsing user list");
127 while ((t
= ConfigParser::strtokFile())) {
128 debugs(28, 6, "aclParseUserList: Got token: " << t
);
130 if (flags
.case_insensitive
)
133 names
= names
->insert(xstrdup(t
), splaystrcmp
);
138 ACLUserData::empty() const
140 return names
->empty() && !flags
.required
;
143 ACLData
<char const *> *
144 ACLUserData::clone() const
146 /* Splay trees don't clone yet. */
148 return new ACLUserData
;