]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/UserData.cc
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/Checklist.h"
37 #include "acl/UserData.h"
38 #include "ConfigParser.h"
48 ACLUserData::~ACLUserData()
51 names
->destroy(xRefFree
);
55 splaystrcasecmp (char * const &l
, char * const &r
)
57 return strcasecmp ((char *)l
,(char *)r
);
61 splaystrcmp (char * const &l
, char * const &r
)
63 return strcmp ((char *)l
,(char *)r
);
67 ACLUserData::match(char const *user
)
69 SplayNode
<char *> *Top
= names
;
71 debugs(28, 7, "aclMatchUser: user is " << user
<< ", case_insensitive is " << flags
.case_insensitive
);
72 debugs(28, 8, "Top is " << Top
<< ", Top->data is " << ((char *) (Top
!= NULL
? (Top
)->data
: "Unavailable")));
74 if (user
== NULL
|| strcmp(user
, "-") == 0)
78 debugs(28, 7, "aclMatchUser: user REQUIRED and auth-info present.");
82 if (flags
.case_insensitive
)
83 Top
= Top
->splay((char *)user
, splaystrcasecmp
);
85 Top
= Top
->splay((char *)user
, splaystrcmp
);
87 /* Top=splay_splay(user,Top,(splayNode::SPLAYCMP *)dumping_strcmp); */
88 debugs(28, 7, "aclMatchUser: returning " << !splayLastResult
<< ",Top is " <<
89 Top
<< ", Top->data is " << ((char *) (Top
? Top
->data
: "Unavailable")));
93 return !splayLastResult
;
97 aclDumpUserListWalkee(char * const & node_data
, void *outlist
)
99 /* outlist is really a SBufList* */
100 static_cast<SBufList
*>(outlist
)->push_back(SBuf(node_data
));
104 ACLUserData::dump() const
108 if (flags
.case_insensitive
)
109 sl
.push_back(SBuf("-i"));
111 /* damn this is VERY inefficient for long ACL lists... filling
112 * a SBufList this way costs Sum(1,N) iterations. For instance
113 * a 1000-elements list will be filled in 499500 iterations.
116 sl
.push_back(SBuf("REQUIRED"));
118 names
->walk(aclDumpUserListWalkee
, &sl
);
126 debugs(28, 2, "aclParseUserList: parsing user list");
129 if ((t
= ConfigParser::strtokFile())) {
130 debugs(28, 5, "aclParseUserList: First token is " << t
);
132 if (strcmp("-i", t
) == 0) {
133 debugs(28, 5, "aclParseUserList: Going case-insensitive");
134 flags
.case_insensitive
= true;
135 } else if (strcmp("REQUIRED", t
) == 0) {
136 debugs(28, 5, "aclParseUserList: REQUIRED-type enabled");
137 flags
.required
= true;
139 if (flags
.case_insensitive
)
142 names
= names
->insert(xstrdup(t
), splaystrcmp
);
146 debugs(28, 3, "aclParseUserList: Case-insensitive-switch is " << flags
.case_insensitive
);
147 /* we might inherit from a previous declaration */
149 debugs(28, 4, "aclParseUserList: parsing user list");
151 while ((t
= ConfigParser::strtokFile())) {
152 debugs(28, 6, "aclParseUserList: Got token: " << t
);
154 if (flags
.case_insensitive
)
157 names
= names
->insert(xstrdup(t
), splaystrcmp
);
162 ACLUserData::empty() const
164 return names
->empty() && !flags
.required
;
167 ACLData
<char const *> *
168 ACLUserData::clone() const
170 /* Splay trees don't clone yet. */
172 return new ACLUserData
;