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"
17 #include "SBufAlgos.h"
21 ACLUserData::match(char const *user
)
23 debugs(28, 7, "user is " << user
<< ", case_insensitive is " << flags
.case_insensitive
);
25 if (user
== NULL
|| strcmp(user
, "-") == 0)
29 debugs(28, 7, "aclMatchUser: user REQUIRED and auth-info present.");
33 bool result
= (userDataNames
.find(SBuf(user
)) != userDataNames
.end());
34 debugs(28, 7, "returning " << result
);
39 ACLUserData::dump() const
44 sl
.push_back(SBuf("REQUIRED"));
48 if (flags
.case_insensitive
)
49 sl
.push_back(SBuf("-i"));
51 sl
.insert(sl
.end(), userDataNames
.begin(), userDataNames
.end());
53 debugs(28,5, "ACLUserData dump output: " << SBufContainerJoin(userDataNames
,SBuf(" ")));
58 CaseInsensitveSBufCompare(const SBuf
&lhs
, const SBuf
&rhs
)
60 return (lhs
.caseCmp(rhs
) < 0);
64 CaseSensitveSBufCompare(const SBuf
&lhs
, const SBuf
&rhs
)
69 ACLUserData::ACLUserData() : userDataNames(CaseSensitveSBufCompare
)
76 debugs(28, 2, "parsing user list");
79 if ((t
= ConfigParser::strtokFile())) {
81 debugs(28, 5, "first token is " << s
);
83 if (s
.cmp("-i",2) == 0) {
84 debugs(28, 5, "Going case-insensitive");
85 flags
.case_insensitive
= true;
86 // due to how the std::set API work, if we want to change
87 // the comparison function we have to create a new std::set
88 UserDataNames_t
newUdn(CaseInsensitveSBufCompare
);
89 newUdn
.insert(userDataNames
.begin(), userDataNames
.end());
90 swap(userDataNames
,newUdn
);
91 } else if (s
.cmp("REQUIRED") == 0) {
92 debugs(28, 5, "REQUIRED-type enabled");
93 flags
.required
= true;
95 if (flags
.case_insensitive
)
98 debugs(28, 6, "Adding user " << s
);
99 userDataNames
.insert(s
);
103 debugs(28, 3, "Case-insensitive-switch is " << flags
.case_insensitive
);
104 /* we might inherit from a previous declaration */
106 debugs(28, 4, "parsing following tokens");
108 while ((t
= ConfigParser::strtokFile())) {
110 debugs(28, 6, "Got token: " << s
);
112 if (flags
.case_insensitive
)
115 debugs(28, 6, "Adding user " << s
);
116 userDataNames
.insert(s
);
119 if (flags
.required
&& !userDataNames
.empty()) {
120 debugs(28, DBG_PARSE_NOTE(1), "WARNING: detected attempt to add usernames to an acl of type REQUIRED");
121 userDataNames
.clear();
124 debugs(28,4, "ACL contains " << userDataNames
.size() << " users");
128 ACLUserData::empty() const
130 debugs(28,6,"required: " << flags
.required
<< ", number of users: " << userDataNames
.size());
133 return userDataNames
.empty();
136 ACLData
<char const *> *
137 ACLUserData::clone() const
139 return new ACLUserData
;