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"
19 ACLUserData::~ACLUserData()
24 ACLUserData::match(char const *user
)
26 debugs(28, 7, "user is " << user
<< ", case_insensitive is " << flags
.case_insensitive
);
28 if (user
== NULL
|| strcmp(user
, "-") == 0)
32 debugs(28, 7, "aclMatchUser: user REQUIRED and auth-info present.");
36 bool result
= (userDataNames
.find(SBuf(user
)) != userDataNames
.end());
37 debugs(28, 7, "returning " << result
);
42 ACLUserData::dump() const
46 if (flags
.case_insensitive
)
47 sl
.push_back(SBuf("-i"));
50 sl
.push_back(SBuf("REQUIRED"));
52 sl
.insert(sl
.end(), userDataNames
.begin(), userDataNames
.end());
58 CaseInsensitveSBufCompare(const SBuf
&lhs
, const SBuf
&rhs
)
60 return (lhs
.caseCmp(rhs
) < 0);
66 debugs(28, 2, "parsing user list");
69 if ((t
= ConfigParser::strtokFile())) {
71 debugs(28, 5, "first token is " << s
);
73 if (s
.cmp("-i",2) == 0) {
74 debugs(28, 5, "Going case-insensitive");
75 flags
.case_insensitive
= true;
76 // due to how the std::set API work, if we want to change
77 // the comparison function we have to create a new std::set
78 UserDataNames_t
newUdn(CaseInsensitveSBufCompare
);
79 newUdn
.insert(userDataNames
.begin(), userDataNames
.end());
80 swap(userDataNames
,newUdn
);
81 } else if (s
.cmp("REQUIRED") == 0) {
82 debugs(28, 5, "REQUIRED-type enabled");
83 flags
.required
= true;
85 if (flags
.case_insensitive
)
88 debugs(28, 6, "Adding user " << s
);
89 userDataNames
.insert(s
);
93 debugs(28, 3, "Case-insensitive-switch is " << flags
.case_insensitive
);
94 /* we might inherit from a previous declaration */
96 debugs(28, 4, "parsing following tokens");
98 while ((t
= ConfigParser::strtokFile())) {
100 debugs(28, 6, "Got token: " << s
);
102 if (flags
.case_insensitive
)
105 debugs(28, 6, "Adding user " << s
);
106 userDataNames
.insert(s
);
109 if (flags
.required
&& !userDataNames
.empty()) {
110 debugs(28, DBG_PARSE_NOTE(1), "WARNING: detected attempt to add usernames to an acl of type REQUIRED");
111 userDataNames
.clear();
114 debugs(28,4, "ACL contains " << userDataNames
.size() << " users");
118 ACLUserData::empty() const
120 debugs(28,6,"required: " << flags
.required
<< ", number of users: " << userDataNames
.size());
123 return userDataNames
.empty();
126 ACLData
<char const *> *
127 ACLUserData::clone() const
129 return new ACLUserData
;