]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/UserData.cc
4 * DEBUG: section 28 Access Control
5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
38 #include "acl/UserData.h"
39 #include "acl/Checklist.h"
42 #include "ConfigParser.h"
51 ACLUserData::~ACLUserData()
54 names
->destroy(xRefFree
);
58 splaystrcasecmp (char * const &l
, char * const &r
)
60 return strcasecmp ((char *)l
,(char *)r
);
64 splaystrcmp (char * const &l
, char * const &r
)
66 return strcmp ((char *)l
,(char *)r
);
70 ACLUserData::match(char const *user
)
72 SplayNode
<char *> *Top
= names
;
74 debugs(28, 7, "aclMatchUser: user is " << user
<< ", case_insensitive is " << flags
.case_insensitive
);
75 debugs(28, 8, "Top is " << Top
<< ", Top->data is " << ((char *) (Top
!= NULL
? (Top
)->data
: "Unavailable")));
77 if (user
== NULL
|| strcmp(user
, "-") == 0)
81 debugs(28, 7, "aclMatchUser: user REQUIRED and auth-info present.");
85 if (flags
.case_insensitive
)
86 Top
= Top
->splay((char *)user
, splaystrcasecmp
);
88 Top
= Top
->splay((char *)user
, splaystrcmp
);
90 /* Top=splay_splay(user,Top,(splayNode::SPLAYCMP *)dumping_strcmp); */
91 debugs(28, 7, "aclMatchUser: returning " << !splayLastResult
<< ",Top is " <<
92 Top
<< ", Top->data is " << ((char *) (Top
? Top
->data
: "Unavailable")));
96 return !splayLastResult
;
100 aclDumpUserListWalkee(char * const & node_data
, void *outlist
)
102 /* outlist is really a wordlist ** */
103 wordlistAdd((wordlist
**)outlist
, (char const *)node_data
);
111 if (flags
.case_insensitive
)
112 wordlistAdd(&wl
, "-i");
114 /* damn this is VERY inefficient for long ACL lists... filling
115 * a wordlist this way costs Sum(1,N) iterations. For instance
116 * a 1000-elements list will be filled in 499500 iterations.
119 wordlistAdd(&wl
, "REQUIRED");
121 names
->walk(aclDumpUserListWalkee
, &wl
);
129 debugs(28, 2, "aclParseUserList: parsing user list");
132 if ((t
= ConfigParser::strtokFile())) {
133 debugs(28, 5, "aclParseUserList: First token is " << t
);
135 if (strcmp("-i", t
) == 0) {
136 debugs(28, 5, "aclParseUserList: Going case-insensitive");
137 flags
.case_insensitive
= 1;
138 } else if (strcmp("REQUIRED", t
) == 0) {
139 debugs(28, 5, "aclParseUserList: REQUIRED-type enabled");
142 if (flags
.case_insensitive
)
145 names
= names
->insert(xstrdup(t
), splaystrcmp
);
149 debugs(28, 3, "aclParseUserList: Case-insensitive-switch is " << flags
.case_insensitive
);
150 /* we might inherit from a previous declaration */
152 debugs(28, 4, "aclParseUserList: parsing user list");
154 while ((t
= ConfigParser::strtokFile())) {
155 debugs(28, 6, "aclParseUserList: Got token: " << t
);
157 if (flags
.case_insensitive
)
160 names
= names
->insert(xstrdup(t
), splaystrcmp
);
166 ACLUserData::empty() const
168 return names
->empty() && !flags
.required
;
171 ACLData
<char const *> *
172 ACLUserData::clone() const
174 /* Splay trees don't clone yet. */
176 return new ACLUserData
;