2 * Copyright (C) 1996-2017 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/FilledChecklist.h"
14 #include "auth/AclMaxUserIp.h"
15 #include "auth/UserRequest.h"
16 #include "ConfigParser.h"
21 ACLFlag
ACLMaxUserIP::SupportedFlags
[] = {ACL_F_STRICT
, ACL_F_END
};
23 ACLMaxUserIP::ACLMaxUserIP(char const *theClass
) :
29 ACLMaxUserIP::ACLMaxUserIP(ACLMaxUserIP
const &old
) :
36 ACLMaxUserIP::~ACLMaxUserIP()
40 ACLMaxUserIP::clone() const
42 return new ACLMaxUserIP(*this);
46 ACLMaxUserIP::typeString() const
52 ACLMaxUserIP::empty() const
58 ACLMaxUserIP::valid() const
67 debugs(28, DBG_IMPORTANT
, "Attempting to alter already set User max IP acl");
71 char *t
= ConfigParser::strtokFile();
76 debugs(28, 5, "aclParseUserMaxIP: First token is " << t
);
80 debugs(28, 5, "aclParseUserMaxIP: Max IP address's " << maximum
);
86 * aclMatchUserMaxIP - check for users logging in from multiple IP's
91 ACLMaxUserIP::match(Auth::UserRequest::Pointer auth_user_request
, Ip::Address
const &src_addr
)
94 * the logic for flush the ip list when the limit is hit vs keep
95 * it sorted in most recent access order and just drop the oldest
96 * one off is currently undecided (RBC)
99 if (authenticateAuthUserRequestIPCount(auth_user_request
) <= maximum
)
102 debugs(28, DBG_IMPORTANT
, "aclMatchUserMaxIP: user '" << auth_user_request
->username() << "' tries to use too many IP addresses (max " << maximum
<< " allowed)!");
104 /* this is a match */
105 if (flags
.isSet(ACL_F_STRICT
)) {
107 * simply deny access - the user name is already associated with
110 /* remove _this_ ip, as it is the culprit for going over the limit */
111 authenticateAuthUserRequestRemoveIp(auth_user_request
, src_addr
);
112 debugs(28, 4, "aclMatchUserMaxIP: Denying access in strict mode");
115 * non-strict - remove some/all of the cached entries
116 * ie to allow the user to move machines easily
118 authenticateAuthUserRequestClearIp(auth_user_request
);
119 debugs(28, 4, "aclMatchUserMaxIP: Denying access in non-strict mode - flushing the user ip cache");
126 ACLMaxUserIP::match(ACLChecklist
*cl
)
128 ACLFilledChecklist
*checklist
= Filled(cl
);
129 allow_t answer
= AuthenticateAcl(checklist
);
132 // convert to tri-state ACL match 1,0,-1
136 ti
= match(checklist
->auth_user_request
, checklist
->src_addr
);
137 checklist
->auth_user_request
= NULL
;
141 return 0; // non-match
144 case ACCESS_AUTH_REQUIRED
:
146 // If the answer is not allowed or denied (matches/not matches) and
147 // async authentication is not in progress, then we are done.
148 if (checklist
->keepMatching())
149 checklist
->markFinished(answer
, "AuthenticateAcl exception");
155 ACLMaxUserIP::dump() const
161 s
.Printf("%d", maximum
);