From: Amos Jeffries Date: Tue, 19 Jun 2012 23:16:13 +0000 (+1200) Subject: Cleanup: disconnect Authentication and URL-rewrite callback handlers X-Git-Tag: sourceformat-review-1~210 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4c535e8712b5b4008e78c60ccda9a464d8eee4b9;p=thirdparty%2Fsquid.git Cleanup: disconnect Authentication and URL-rewrite callback handlers The authentication handlers were for some reason using RH (rewrite helper) callback typedef. But specifying it as a fatal error if the char* parameter was used in auth. Assign a new callback typedef AUTHCB for use by authentication callers. This allows auth callers to use different parameters (none) and to avoid possibly fatal mistakes when coding new auth modules. --- diff --git a/src/auth/AclProxyAuth.cc b/src/auth/AclProxyAuth.cc index f2c48f95c0..69f29ede46 100644 --- a/src/auth/AclProxyAuth.cc +++ b/src/auth/AclProxyAuth.cc @@ -152,15 +152,12 @@ ProxyAuthLookup::checkForAsync(ACLChecklist *cl)const } void -ProxyAuthLookup::LookupDone(void *data, char *result) +ProxyAuthLookup::LookupDone(void *data) { ACLFilledChecklist *checklist = Filled(static_cast(data)); assert (checklist->asyncState() == ProxyAuthLookup::Instance()); - if (result != NULL) - fatal("AclLookupProxyAuthDone: Old code floating around somewhere.\nMake clean and if that doesn't work, report a bug to the squid developers.\n"); - if (checklist->auth_user_request == NULL || !checklist->auth_user_request->valid() || checklist->conn() == NULL) { /* credentials could not be checked either way * restart the whole process */ diff --git a/src/auth/AclProxyAuth.h b/src/auth/AclProxyAuth.h index 5d0503d710..4be089198e 100644 --- a/src/auth/AclProxyAuth.h +++ b/src/auth/AclProxyAuth.h @@ -50,7 +50,7 @@ public: private: static ProxyAuthLookup instance_; - static void LookupDone(void *data, char *result); + static void LookupDone(void *data); }; class ACLProxyAuth : public ACL diff --git a/src/auth/State.h b/src/auth/State.h index c3c215841f..5722f2ad09 100644 --- a/src/auth/State.h +++ b/src/auth/State.h @@ -15,7 +15,7 @@ namespace Auth class StateData { public: - StateData(const UserRequest::Pointer &r, RH *h, void *d) : + StateData(const UserRequest::Pointer &r, AUTHCB *h, void *d) : data(cbdataReference(d)), auth_user_request(r), handler(h) {} @@ -27,7 +27,7 @@ public: void *data; UserRequest::Pointer auth_user_request; - RH *handler; + AUTHCB *handler; private: CBDATA_CLASS2(StateData); diff --git a/src/auth/UserRequest.cc b/src/auth/UserRequest.cc index 7ba7ebaf5d..198790efcc 100644 --- a/src/auth/UserRequest.cc +++ b/src/auth/UserRequest.cc @@ -63,7 +63,7 @@ Auth::UserRequest::username() const /* send the initial data to an authenticator module */ void -Auth::UserRequest::start(RH * handler, void *data) +Auth::UserRequest::start(AUTHCB * handler, void *data) { assert(handler); assert(data); diff --git a/src/auth/UserRequest.h b/src/auth/UserRequest.h index b420cbaffd..808324c63e 100644 --- a/src/auth/UserRequest.h +++ b/src/auth/UserRequest.h @@ -66,6 +66,9 @@ public: time_t ip_expiretime; }; +// TODO: make auth schedule AsyncCalls? +typedef void AUTHCB(void*); + namespace Auth { @@ -156,7 +159,7 @@ public: * \param handler Handler to process the callback when its run * \param data CBDATA for handler */ - virtual void module_start(RH *handler, void *data) = 0; + virtual void module_start(AUTHCB *handler, void *data) = 0; // User credentials object this UserRequest is managing virtual User::Pointer user() {return _auth_user;} @@ -186,7 +189,7 @@ public: /// Add the appropriate [Proxy-]Authenticate header to the given reply static void addReplyAuthHeader(HttpReply * rep, UserRequest::Pointer auth_user_request, HttpRequest * request, int accelerated, int internal); - void start( RH * handler, void *data); + void start(AUTHCB *handler, void *data); char const * denyMessage(char const * const default_message = NULL); /** Possibly overrideable in future */ diff --git a/src/auth/basic/UserRequest.cc b/src/auth/basic/UserRequest.cc index 0efa5adb5c..fc07a5d6ac 100644 --- a/src/auth/basic/UserRequest.cc +++ b/src/auth/basic/UserRequest.cc @@ -77,7 +77,7 @@ Auth::Basic::UserRequest::module_direction() /* send the initial data to a basic authenticator module */ void -Auth::Basic::UserRequest::module_start(RH * handler, void *data) +Auth::Basic::UserRequest::module_start(AUTHCB * handler, void *data) { assert(user()->auth_type == Auth::AUTH_BASIC); Auth::Basic::User *basic_auth = dynamic_cast(user().getRaw()); @@ -86,7 +86,7 @@ Auth::Basic::UserRequest::module_start(RH * handler, void *data) if (static_cast(Auth::Config::Find("basic"))->authenticateProgram == NULL) { debugs(29, DBG_CRITICAL, "ERROR: No Basic authentication program configured."); - handler(data, NULL); + handler(data); return; } @@ -124,10 +124,10 @@ Auth::Basic::UserRequest::module_start(RH * handler, void *data) int sz = snprintf(buf, sizeof(buf), "%s %s\n", username, pass); if (sz<=0) { debugs(9, DBG_CRITICAL, "ERROR: Basic Authentication Failure. Can not build helper validation request."); - handler(data, NULL); + handler(data); } else if (static_cast(sz) >= sizeof(buf)) { debugs(9, DBG_CRITICAL, "ERROR: Basic Authentication Failure. user:password exceeds " << sizeof(buf) << " bytes."); - handler(data, NULL); + handler(data); } else helperSubmit(basicauthenticators, buf, Auth::Basic::UserRequest::HandleReply, new Auth::StateData(this, handler, data)); @@ -171,7 +171,7 @@ Auth::Basic::UserRequest::HandleReply(void *data, char *reply) basic_auth->expiretime = squid_curtime; if (cbdataReferenceValidDone(r->data, &cbdata)) - r->handler(cbdata, NULL); + r->handler(cbdata); cbdataReferenceDone(r->data); @@ -179,7 +179,7 @@ Auth::Basic::UserRequest::HandleReply(void *data, char *reply) tmpnode = basic_auth->auth_queue->next; if (cbdataReferenceValidDone(basic_auth->auth_queue->data, &cbdata)) - basic_auth->auth_queue->handler(cbdata, NULL); + basic_auth->auth_queue->handler(cbdata); xfree(basic_auth->auth_queue); diff --git a/src/auth/basic/UserRequest.h b/src/auth/basic/UserRequest.h index febe4453ad..304e8cf9df 100644 --- a/src/auth/basic/UserRequest.h +++ b/src/auth/basic/UserRequest.h @@ -26,7 +26,7 @@ public: virtual int authenticated() const; virtual void authenticate(HttpRequest * request, ConnStateData *conn, http_hdr_type type); virtual Auth::Direction module_direction(); - virtual void module_start(RH *, void *); + virtual void module_start(AUTHCB *, void *); private: static HLPCB HandleReply; diff --git a/src/auth/basic/auth_basic.h b/src/auth/basic/auth_basic.h index 405002a0b7..e519fab8da 100644 --- a/src/auth/basic/auth_basic.h +++ b/src/auth/basic/auth_basic.h @@ -20,7 +20,7 @@ class BasicAuthQueueNode public: BasicAuthQueueNode *next; Auth::UserRequest::Pointer auth_user_request; - RH *handler; + AUTHCB *handler; void *data; }; diff --git a/src/auth/digest/UserRequest.cc b/src/auth/digest/UserRequest.cc index ef76ff49b0..92972fdf0c 100644 --- a/src/auth/digest/UserRequest.cc +++ b/src/auth/digest/UserRequest.cc @@ -245,7 +245,7 @@ Auth::Digest::UserRequest::addAuthenticationInfoTrailer(HttpReply * rep, int acc /* send the initial data to a digest authenticator module */ void -Auth::Digest::UserRequest::module_start(RH * handler, void *data) +Auth::Digest::UserRequest::module_start(AUTHCB * handler, void *data) { char buf[8192]; @@ -254,7 +254,7 @@ Auth::Digest::UserRequest::module_start(RH * handler, void *data) if (static_cast(Auth::Config::Find("digest"))->authenticateProgram == NULL) { debugs(29, DBG_CRITICAL, "ERROR: No Digest authentication program configured."); - handler(data, NULL); + handler(data); return; } @@ -309,7 +309,7 @@ Auth::Digest::UserRequest::HandleReply(void *data, char *reply) } if (cbdataReferenceValidDone(replyData->data, &cbdata)) - replyData->handler(cbdata, NULL); + replyData->handler(cbdata); delete replyData; } diff --git a/src/auth/digest/UserRequest.h b/src/auth/digest/UserRequest.h index af2d7fc8d4..011be30dab 100644 --- a/src/auth/digest/UserRequest.h +++ b/src/auth/digest/UserRequest.h @@ -34,7 +34,7 @@ public: virtual void addAuthenticationInfoTrailer(HttpReply * rep, int accel); #endif - virtual void module_start(RH *, void *); + virtual void module_start(AUTHCB *, void *); char *nonceb64; /* "dcd98b7102dd2f0e8b11d0f600bfb0c093" */ char *cnonce; /* "0a4f113b" */ diff --git a/src/auth/negotiate/UserRequest.cc b/src/auth/negotiate/UserRequest.cc index f0712d66fe..e0fa1964b9 100644 --- a/src/auth/negotiate/UserRequest.cc +++ b/src/auth/negotiate/UserRequest.cc @@ -79,7 +79,7 @@ Auth::Negotiate::UserRequest::module_direction() } void -Auth::Negotiate::UserRequest::module_start(RH * handler, void *data) +Auth::Negotiate::UserRequest::module_start(AUTHCB * handler, void *data) { static char buf[MAX_AUTHTOKEN_LEN]; @@ -91,7 +91,7 @@ Auth::Negotiate::UserRequest::module_start(RH * handler, void *data) if (static_cast(Auth::Config::Find("negotiate"))->authenticateProgram == NULL) { debugs(29, DBG_CRITICAL, "ERROR: No Negotiate authentication program configured."); - handler(data, NULL); + handler(data); return; } @@ -360,7 +360,7 @@ Auth::Negotiate::UserRequest::HandleReply(void *data, void *lastserver, char *re } lm_request->request = NULL; - r->handler(r->data, NULL); + r->handler(r->data); delete r; } diff --git a/src/auth/negotiate/UserRequest.h b/src/auth/negotiate/UserRequest.h index 888cdf93ff..478680cfcd 100644 --- a/src/auth/negotiate/UserRequest.h +++ b/src/auth/negotiate/UserRequest.h @@ -27,7 +27,7 @@ public: virtual void authenticate(HttpRequest * request, ConnStateData * conn, http_hdr_type type); virtual Direction module_direction(); virtual void onConnectionClose(ConnStateData *); - virtual void module_start(RH *, void *); + virtual void module_start(AUTHCB *, void *); virtual void addAuthenticationInfoHeader(HttpReply * rep, int accel); diff --git a/src/auth/ntlm/UserRequest.cc b/src/auth/ntlm/UserRequest.cc index b228d29dac..efdb33d255 100644 --- a/src/auth/ntlm/UserRequest.cc +++ b/src/auth/ntlm/UserRequest.cc @@ -77,7 +77,7 @@ Auth::Ntlm::UserRequest::module_direction() } void -Auth::Ntlm::UserRequest::module_start(RH * handler, void *data) +Auth::Ntlm::UserRequest::module_start(AUTHCB * handler, void *data) { static char buf[MAX_AUTHTOKEN_LEN]; @@ -86,7 +86,7 @@ Auth::Ntlm::UserRequest::module_start(RH * handler, void *data) if (static_cast(Auth::Config::Find("ntlm"))->authenticateProgram == NULL) { debugs(29, DBG_CRITICAL, "ERROR: NTLM Start: no NTLM program configured."); - handler(data, NULL); + handler(data); return; } @@ -340,6 +340,6 @@ Auth::Ntlm::UserRequest::HandleReply(void *data, void *lastserver, char *reply) HTTPMSGUNLOCK(lm_request->request); lm_request->request = NULL; } - r->handler(r->data, NULL); + r->handler(r->data); delete r; } diff --git a/src/auth/ntlm/UserRequest.h b/src/auth/ntlm/UserRequest.h index e999b670c0..82e72b101d 100644 --- a/src/auth/ntlm/UserRequest.h +++ b/src/auth/ntlm/UserRequest.h @@ -27,7 +27,7 @@ public: virtual void authenticate(HttpRequest * request, ConnStateData * conn, http_hdr_type type); virtual Auth::Direction module_direction(); virtual void onConnectionClose(ConnStateData *); - virtual void module_start(RH *, void *); + virtual void module_start(AUTHCB *, void *); virtual const char * connLastHeader();