return auth_user_request->authenticated();
}
-int
+Auth::Direction
AuthUserRequest::direction()
{
+ if (user() == NULL)
+ return Auth::CRED_ERROR; // No credentials. Should this be a CHALLENGE instead?
+
if (authenticateUserAuthenticated(this))
- return 0;
+ return Auth::CRED_VALID;
return module_direction();
}
}
if (!authenticateUserAuthenticated(*auth_user_request)) {
- /* User not logged in. Log them in */
+ /* User not logged in. Try to log them in */
authenticateAuthenticateUser(*auth_user_request, request, conn, headertype);
- switch (authenticateDirection(*auth_user_request)) {
+ switch ((*auth_user_request)->direction()) {
- case 1:
+ case Auth::CRED_CHALLENGE:
if (request->auth_user_request == NULL) {
request->auth_user_request = *auth_user_request;
}
- /* fallthrough to -2 */
+ /* fallthrough to ERROR case and do the challenge */
- case -2:
+ case Auth::CRED_ERROR:
/* this ACL check is finished. */
*auth_user_request = NULL;
return AUTH_ACL_CHALLENGE;
- case -1:
+ case Auth::CRED_LOOKUP:
/* we are partway through authentication within squid,
* the *auth_user_request variables stores the auth_user_request
* for the callback to here - Do not Unlock */
return AUTH_ACL_HELPER;
- }
- /* on 0 the authentication is finished - fallthrough */
- /* See if user authentication failed for some reason */
- if (!authenticateUserAuthenticated(*auth_user_request)) {
- if ((*auth_user_request)->username()) {
- if (!request->auth_user_request) {
- request->auth_user_request = *auth_user_request;
+ case Auth::CRED_VALID:
+ /* authentication is finished */
+ /* See if user authentication failed for some reason */
+ if (!authenticateUserAuthenticated(*auth_user_request)) {
+ if ((*auth_user_request)->username()) {
+ if (!request->auth_user_request) {
+ request->auth_user_request = *auth_user_request;
+ }
}
- }
- *auth_user_request = NULL;
- return AUTH_ACL_CHALLENGE;
+ *auth_user_request = NULL;
+ return AUTH_ACL_CHALLENGE;
+ }
+ // otherwise fallthrough to acceptance.
}
}
return result;
}
-/* returns
- * 0: no output needed
- * 1: send to client
- * -1: send to helper
- * -2: authenticate broken in some fashion
- */
-int
-authenticateDirection(AuthUserRequest::Pointer auth_user_request)
-{
- if (auth_user_request == NULL || auth_user_request->user() == NULL)
- return -2;
-
- return auth_user_request->direction();
-}
-
void
AuthUserRequest::addReplyAuthHeader(HttpReply * rep, AuthUserRequest::Pointer auth_user_request, HttpRequest * request, int accelerated, int internal)
/* send the auth types we are configured to support (and have compiled in!) */
/* this is a authenticate-needed response */
{
- if ((auth_user_request != NULL) && authenticateDirection(auth_user_request) == 1)
- /* scheme specific */
+ if (auth_user_request != NULL && auth_user_request->direction() == Auth::CRED_CHALLENGE)
+ /* add the scheme specific challenge header to the response */
auth_user_request->user()->config->fixHeader(auth_user_request, rep, type, request);
else {
/* call each configured & running authscheme */
time_t ip_expiretime;
};
+namespace Auth
+{
+
+// NP: numeric values specified for old code backward compatibility.
+// remove after transition is complete
+enum Direction {
+ CRED_CHALLENGE = 1, ///< Client needs to be challenged. secure token.
+ CRED_VALID = 0, ///< Credentials are valid and a up to date. The OK/Failed state is accurate.
+ CRED_LOOKUP = -1, ///< Credentials need to be validated with the backend helper
+ CRED_ERROR = -2 ///< ERROR in the auth module. Cannot determine the state of this request.
+};
+} // namespace Auth
+
/**
\ingroup AuthAPI
* This is a short lived structure is the visible aspect of the authentication framework.
/**
* Used by squid to determine what the next step in performing authentication for a given scheme is.
*
- \retval -2 ERROR in the auth module. Cannot determine request direction.
- \retval -1 The auth module needs to send data to an external helper.
- * Squid will prepare for a callback on the request and call the AUTHSSTART function.
- \retval 0 The auth module has all the information it needs to perform the authentication and provide a succeed/fail result.
- \retval 1 The auth module needs to send a new challenge to the request originator.
- * Squid will return the appropriate status code (401 or 407) and call the registered FixError function to allow the auth module to insert it's challenge.
+ * \retval CRED_ERROR ERROR in the auth module. Cannot determine request direction.
+ * \retval CRED_LOOKUP The auth module needs to send data to an external helper.
+ * Squid will prepare for a callback on the request and call the AUTHSSTART function.
+ * \retval CRED_VALID The auth module has all the information it needs to perform the authentication
+ * and provide a succeed/fail result.
+ * \retval CRED_CHALLENGE The auth module needs to send a new challenge to the request originator.
+ * Squid will return the appropriate status code (401 or 407) and call the registered
+ * FixError function to allow the auth module to insert it's challenge.
*/
- int direction();
+ Auth::Direction direction();
/**
* Used by squid to determine whether the auth scheme has successfully authenticated the user request.
virtual void authenticate(HttpRequest * request, ConnStateData * conn, http_hdr_type type) = 0;
/* template method */
- virtual int module_direction() = 0;
+ virtual Auth::Direction module_direction() = 0;
virtual void addHeader(HttpReply * rep, int accel);
virtual void addTrailer(HttpReply * rep, int accel);
virtual void onConnectionClose(ConnStateData *);
extern void authenticateAuthUserRequestClearIp(AuthUserRequest::Pointer);
/// \ingroup AuthAPI
extern int authenticateAuthUserRequestIPCount(AuthUserRequest::Pointer);
-/// \ingroup AuthAPI
-/// \deprecated Use AuthUserRequest::direction() instead.
-extern int authenticateDirection(AuthUserRequest::Pointer);
/// \ingroup AuthAPI
/// See AuthUserRequest::authenticated()
return;
}
-int
+Auth::Direction
AuthBasicUserRequest::module_direction()
{
- /* null auth_user is checked for by authenticateDirection */
+ /* null auth_user is checked for by AuthUserRequest::direction() */
if (user()->auth_type != Auth::AUTH_BASIC)
- return -2;
+ return Auth::CRED_ERROR;
switch (user()->credentials()) {
case Auth::Unchecked:
case Auth::Pending:
- return -1;
+ return Auth::CRED_LOOKUP;
case Auth::Ok:
if (user()->expiretime + static_cast<Auth::Basic::Config*>(Auth::Config::Find("basic"))->credentialsTTL <= squid_curtime)
- return -1;
- return 0;
+ return Auth::CRED_LOOKUP;
+ return Auth::CRED_VALID;
case Auth::Failed:
- return 0;
+ return Auth::CRED_VALID;
default:
- return -2;
+ return Auth::CRED_ERROR;
}
}
virtual int authenticated() const;
virtual void authenticate(HttpRequest * request, ConnStateData *conn, http_hdr_type type);
- virtual int module_direction();
+ virtual Auth::Direction module_direction();
virtual void module_start(RH *, void *);
};
return;
}
-int
+Auth::Direction
AuthDigestUserRequest::module_direction()
{
if (user()->auth_type != Auth::AUTH_DIGEST)
- return -2;
+ return Auth::CRED_ERROR;
switch (user()->credentials()) {
case Auth::Ok:
- return 0;
+ return Auth::CRED_VALID;
case Auth::Failed:
/* send new challenge */
- return 1;
+ return Auth::CRED_CHALLENGE;
case Auth::Unchecked:
case Auth::Pending:
- return -1;
+ return Auth::CRED_LOOKUP;
default:
- return -2;
+ return Auth::CRED_ERROR;
}
}
virtual int authenticated() const;
virtual void authenticate(HttpRequest * request, ConnStateData * conn, http_hdr_type type);
- virtual int module_direction();
+ virtual Auth::Direction module_direction();
virtual void addHeader(HttpReply * rep, int accel);
#if WAITING_FOR_TE
return 0;
}
-/* See AuthUserRequest.cc::authenticateDirection for return values */
-int
+Auth::Direction
AuthNegotiateUserRequest::module_direction()
{
- /* null auth_user is checked for by authenticateDirection */
+ /* null auth_user is checked for by AuthUserRequest::direction() */
if (waiting || client_blob)
- return -1; /* need helper response to continue */
+ return Auth::CRED_LOOKUP; /* need helper response to continue */
if (user()->auth_type != Auth::AUTH_NEGOTIATE)
- return -2;
+ return Auth::CRED_ERROR;
switch (user()->credentials()) {
case Auth::Handshake:
assert(server_blob);
- return 1; /* send to client */
+ return Auth::CRED_CHALLENGE;
case Auth::Ok:
- return 0; /* do nothing */
+ return Auth::CRED_VALID;
case Auth::Failed:
- return -2;
+ return Auth::CRED_ERROR; // XXX: really? not VALID or CHALLENGE?
default:
debugs(29, DBG_IMPORTANT, "WARNING: Negotiate Authentication in unexpected state: " << user()->credentials());
- return -2;
+ return Auth::CRED_ERROR;
}
}
virtual ~AuthNegotiateUserRequest();
virtual int authenticated() const;
virtual void authenticate(HttpRequest * request, ConnStateData * conn, http_hdr_type type);
- virtual int module_direction();
+ virtual Auth::Direction module_direction();
virtual void onConnectionClose(ConnStateData *);
virtual void module_start(RH *, void *);
return NULL;
}
-/* See AuthUserRequest.cc::authenticateDirection for return values */
-int
+Auth::Direction
AuthNTLMUserRequest::module_direction()
{
- /* null auth_user is checked for by authenticateDirection */
+ /* null auth_user is checked for by AuthUserRequest::direction() */
if (waiting || client_blob)
- return -1; /* need helper response to continue */
+ return Auth::CRED_LOOKUP; /* need helper response to continue */
if (user()->auth_type != Auth::AUTH_NTLM)
- return -2;
+ return Auth::CRED_ERROR;
switch (user()->credentials()) {
case Auth::Handshake:
assert(server_blob);
- return 1; /* send to client */
+ return Auth::CRED_CHALLENGE; /* send to client */
case Auth::Ok:
- return 0; /* do nothing */
+ return Auth::CRED_VALID;
case Auth::Failed:
- return -2;
+ return Auth::CRED_ERROR; // XXX really? not VALID or CHALLENGE?
default:
debugs(29, DBG_IMPORTANT, "WARNING: NTLM Authentication in unexpected state: " << user()->credentials());
- return -2;
+ return Auth::CRED_ERROR;
}
}
virtual ~AuthNTLMUserRequest();
virtual int authenticated() const;
virtual void authenticate(HttpRequest * request, ConnStateData * conn, http_hdr_type type);
- virtual int module_direction();
+ virtual Auth::Direction module_direction();
virtual void onConnectionClose(ConnStateData *);
virtual void module_start(RH *, void *);