]>
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/UserData.h"
37 #include "acl/Checklist.h"
40 #include "ConfigParser.h"
49 ACLUserData::~ACLUserData()
52 names
->destroy(xRefFree
);
56 splaystrcasecmp (char * const &l
, char * const &r
)
58 return strcasecmp ((char *)l
,(char *)r
);
62 splaystrcmp (char * const &l
, char * const &r
)
64 return strcmp ((char *)l
,(char *)r
);
68 ACLUserData::match(char const *user
)
70 SplayNode
<char *> *Top
= names
;
72 debugs(28, 7, "aclMatchUser: user is " << user
<< ", case_insensitive is " << flags
.case_insensitive
);
73 debugs(28, 8, "Top is " << Top
<< ", Top->data is " << ((char *) (Top
!= NULL
? (Top
)->data
: "Unavailable")));
75 if (user
== NULL
|| strcmp(user
, "-") == 0)
79 debugs(28, 7, "aclMatchUser: user REQUIRED and auth-info present.");
83 if (flags
.case_insensitive
)
84 Top
= Top
->splay((char *)user
, splaystrcasecmp
);
86 Top
= Top
->splay((char *)user
, splaystrcmp
);
88 /* Top=splay_splay(user,Top,(splayNode::SPLAYCMP *)dumping_strcmp); */
89 debugs(28, 7, "aclMatchUser: returning " << !splayLastResult
<< ",Top is " <<
90 Top
<< ", Top->data is " << ((char *) (Top
? Top
->data
: "Unavailable")));
94 return !splayLastResult
;
98 aclDumpUserListWalkee(char * const & node_data
, void *outlist
)
100 /* outlist is really a wordlist ** */
101 wordlistAdd((wordlist
**)outlist
, (char const *)node_data
);
109 if (flags
.case_insensitive
)
110 wordlistAdd(&wl
, "-i");
112 /* damn this is VERY inefficient for long ACL lists... filling
113 * a wordlist this way costs Sum(1,N) iterations. For instance
114 * a 1000-elements list will be filled in 499500 iterations.
117 wordlistAdd(&wl
, "REQUIRED");
119 names
->walk(aclDumpUserListWalkee
, &wl
);
127 debugs(28, 2, "aclParseUserList: parsing user list");
130 if ((t
= ConfigParser::strtokFile())) {
131 debugs(28, 5, "aclParseUserList: First token is " << t
);
133 if (strcmp("-i", t
) == 0) {
134 debugs(28, 5, "aclParseUserList: Going case-insensitive");
135 flags
.case_insensitive
= 1;
136 } else if (strcmp("REQUIRED", t
) == 0) {
137 debugs(28, 5, "aclParseUserList: REQUIRED-type enabled");
140 if (flags
.case_insensitive
)
143 names
= names
->insert(xstrdup(t
), splaystrcmp
);
147 debugs(28, 3, "aclParseUserList: Case-insensitive-switch is " << flags
.case_insensitive
);
148 /* we might inherit from a previous declaration */
150 debugs(28, 4, "aclParseUserList: parsing user list");
152 while ((t
= ConfigParser::strtokFile())) {
153 debugs(28, 6, "aclParseUserList: Got token: " << t
);
155 if (flags
.case_insensitive
)
158 names
= names
->insert(xstrdup(t
), splaystrcmp
);
163 ACLUserData::empty() const
165 return names
->empty() && !flags
.required
;
168 ACLData
<char const *> *
169 ACLUserData::clone() const
171 /* Splay trees don't clone yet. */
173 return new ACLUserData
;