# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: henrik@henriknordstrom.net-20090826120021-\
#   pb2rqz639jzlxa6m
# target_branch: http://www.squid-cache.org/bzr/squid3/trunk/
# testament_sha1: 7fc1901a75d5f7bef631559a600be5c596b94386
# timestamp: 2009-08-26 14:00:46 +0200
# base_revision_id: kinkie@squid-cache.org-20090825171158-\
#   8j8sboc0fjzyhial
# 
# Begin patch
=== modified file 'src/cf.data.pre'
--- src/cf.data.pre	2009-08-25 11:31:30 +0000
+++ src/cf.data.pre	2009-08-26 11:43:52 +0000
@@ -1797,30 +1797,14 @@
 			Note: This will pass any form of authentication but
 			only Basic auth will work through a proxy unless the
 			connection-auth options are also used.
-	
-	login=PROXYPASS
-			Send login details received from client to this peer.
-			Only WWW-Authorization headers are passed to the peer.
-			If the 'originserver' option is also used this will
-			convert Proxy-Authorization: to WWW-Authorization: before
-			relaying. The header content is not altered.
-			
-			Authentication is not required by Squid for this to work
-			however it should be noted that without it somewhere down
-			the proxy chain there may be no Proxy-Authorization:
-			header to convert.
-			
-			Note: This will pass any form of authentication but
-			only Basic auth will work through a proxy unless the
-			connection-auth options are also used.
-	
+
 	login=PASS	Send login details received from client to this peer.
 			Authentication is not required by this option.
 			
 			If there are no client-provided authentication headers
 			to pass on, but username and password are available
-			from either proxy login or an external ACL user= and
-			password= result tags they may be sent instead.
+			from an external ACL user= and password= result tags
+			they may be sent instead.
 			
 			Note: To combine this with proxy_auth both proxies must
 			share the same user database as HTTP only allows for

=== modified file 'src/http.cc'
--- src/http.cc	2009-08-25 11:31:30 +0000
+++ src/http.cc	2009-08-26 12:00:21 +0000
@@ -1446,6 +1446,76 @@
     return fd < 0;
 }
 
+
+/*
+ * Fixup authentication request headers for special cases
+ */
+static void
+httpFixupAuthentication(HttpRequest * request, HttpRequest * orig_request, const HttpHeader * hdr_in, HttpHeader * hdr_out, http_state_flags flags)
+{
+    http_hdr_type header = flags.originpeer ? HDR_AUTHORIZATION : HDR_PROXY_AUTHORIZATION;
+
+    /* Nothing to do unless we are forwarding to a peer */
+    if (!request->flags.proxying)
+	return;
+
+    /* Needs to be explicitly enabled */
+    if (!orig_request->peer_login)
+	return;
+
+    /* Maybe already dealt with? */
+    if (hdr_out->has(header))
+	return;
+
+    /* Nothing to do here for PASSTHRU */
+    if (strcmp(orig_request->peer_login, "PASSTHRU") == 0)
+	return;
+
+    /* PROXYPASS is a special case, single-signon to servers with the proxy password (basic only) */
+    if (flags.originpeer && strcmp(orig_request->peer_login, "PROXYPASS") == 0 && hdr_in->has(HDR_PROXY_AUTHORIZATION)) {
+	const char *auth = hdr_in->getStr(HDR_PROXY_AUTHORIZATION);
+
+	if (auth && strncasecmp(auth, "basic ", 6) == 0) {
+	    hdr_out->putStr(header, auth);
+	    return;
+	}
+    }
+
+    /* Special mode to pass the username to the upstream cache */
+    if (*orig_request->peer_login == '*') {
+	char loginbuf[256];
+	const char *username = "-";
+
+	if (orig_request->extacl_user.size())
+	    username = orig_request->extacl_user.termedBuf();
+	else if (orig_request->auth_user_request)
+	    username = orig_request->auth_user_request->username();
+
+	snprintf(loginbuf, sizeof(loginbuf), "%s%s", username, orig_request->peer_login + 1);
+
+	httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
+			  base64_encode(loginbuf));
+	return;
+    }
+
+    /* external_acl provided credentials */
+    if (orig_request->extacl_user.size() && orig_request->extacl_passwd.size() &&
+	    (strcmp(orig_request->peer_login, "PASS") == 0 ||
+	     strcmp(orig_request->peer_login, "PROXYPASS"))) {
+	char loginbuf[256];
+	snprintf(loginbuf, sizeof(loginbuf), SQUIDSTRINGPH ":" SQUIDSTRINGPH,
+		 SQUIDSTRINGPRINT(orig_request->extacl_user),
+		 SQUIDSTRINGPRINT(orig_request->extacl_passwd));
+	httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
+			  base64_encode(loginbuf));
+	return;
+    }
+
+    httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
+		      base64_encode(orig_request->peer_login));
+    return;
+}
+
 /*
  * build request headers and append them to a given MemBuf
  * used by buildRequestPrefix()
@@ -1576,87 +1646,11 @@
         }
     }
 
-    /* append Proxy-Authorization if configured for peer, and proxying */
-    if (request->flags.proxying && orig_request->peer_login &&
-            !hdr_out->has(HDR_PROXY_AUTHORIZATION)) {
-        if (*orig_request->peer_login == '*') {
-            /* Special mode, to pass the username to the upstream cache */
-            char loginbuf[256];
-            const char *username = "-";
-
-            if (orig_request->extacl_user.size())
-                username = orig_request->extacl_user.termedBuf();
-            else if (orig_request->auth_user_request)
-                username = orig_request->auth_user_request->username();
-
-            snprintf(loginbuf, sizeof(loginbuf), "%s%s", username, orig_request->peer_login + 1);
-
-            httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
-                              base64_encode(loginbuf));
-        } else if (strcmp(orig_request->peer_login, "PASS") == 0) {
-            if (orig_request->extacl_user.size() && orig_request->extacl_passwd.size()) {
-                char loginbuf[256];
-                snprintf(loginbuf, sizeof(loginbuf), SQUIDSTRINGPH ":" SQUIDSTRINGPH,
-                         SQUIDSTRINGPRINT(orig_request->extacl_user),
-                         SQUIDSTRINGPRINT(orig_request->extacl_passwd));
-                httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
-                                  base64_encode(loginbuf));
-            }
-        } else if (strcmp(orig_request->peer_login, "PROXYPASS") == 0) {
-            /* Nothing to do */
-        } else if (strcmp(orig_request->peer_login, "PASSTHRU") == 0) {
-            /* Nothing to do (yet) */
-        } else {
-            httpHeaderPutStrf(hdr_out, HDR_PROXY_AUTHORIZATION, "Basic %s",
-                              base64_encode(orig_request->peer_login));
-        }
-    }
-
-    /* append WWW-Authorization if configured for peer */
-    if (flags.originpeer && orig_request->peer_login &&
-            !hdr_out->has(HDR_AUTHORIZATION)) {
-        if (strcmp(orig_request->peer_login, "PASS") == 0) {
-            /* No credentials to forward.. (should have been done above if available) */
-        } else if (strcmp(orig_request->peer_login, "PASSTHRU") == 0) {
-            /* Nothing to do (yet) */
-        } else if (strcmp(orig_request->peer_login, "PROXYPASS") == 0) {
-            /* Special mode, convert proxy authentication to WWW authentication
-            * (also applies to authentication provided by external acl)
-             */
-            const char *auth = hdr_in->getStr(HDR_PROXY_AUTHORIZATION);
-
-            if (auth && strncasecmp(auth, "basic ", 6) == 0) {
-                hdr_out->putStr(HDR_AUTHORIZATION, auth);
-            } else if (orig_request->extacl_user.size() && orig_request->extacl_passwd.size()) {
-                char loginbuf[256];
-                snprintf(loginbuf, sizeof(loginbuf), SQUIDSTRINGPH ":" SQUIDSTRINGPH,
-                         SQUIDSTRINGPRINT(orig_request->extacl_user),
-                         SQUIDSTRINGPRINT(orig_request->extacl_passwd));
-                httpHeaderPutStrf(hdr_out, HDR_AUTHORIZATION, "Basic %s",
-                                  base64_encode(loginbuf));
-            }
-        } else if (*orig_request->peer_login == '*') {
-            /* Special mode, to pass the username to the upstream cache */
-            char loginbuf[256];
-            const char *username = "-";
-
-            if (orig_request->auth_user_request)
-                username = orig_request->auth_user_request->username();
-            else if (orig_request->extacl_user.size())
-                username = orig_request->extacl_user.termedBuf();
-
-            snprintf(loginbuf, sizeof(loginbuf), "%s%s", username, orig_request->peer_login + 1);
-
-            httpHeaderPutStrf(hdr_out, HDR_AUTHORIZATION, "Basic %s",
-                              base64_encode(loginbuf));
-        } else {
-            /* Fixed login string */
-            httpHeaderPutStrf(hdr_out, HDR_AUTHORIZATION, "Basic %s",
-                              base64_encode(orig_request->peer_login));
-        }
-    }
-
-    /* append Cache-Control, add max-age if not there already */ {
+    /* Fixup (Proxy-)Authorization special cases. Plain relaying dealt with above */
+    httpFixupAuthentication(request, orig_request, hdr_in, hdr_out, flags);
+
+    /* append Cache-Control, add max-age if not there already */
+    {
         HttpHdrCc *cc = hdr_in->getCc();
 
         if (!cc)
@@ -1727,9 +1721,10 @@
          * Only pass on proxy authentication to peers for which
          * authentication forwarding is explicitly enabled
          */
-        if (flags.proxying && orig_request->peer_login &&
-                (strcmp(orig_request->peer_login, "PASS") == 0 ||
-                 strcmp(orig_request->peer_login, "PASSTHRU") == 0)) {
+        if (!flags.originpeer && flags.proxying && orig_request->peer_login &&
+		(strcmp(orig_request->peer_login, "PASS") == 0 ||
+		 strcmp(orig_request->peer_login, "PROXYPASS") == 0 ||
+		 strcmp(orig_request->peer_login, "PASSTHRU") == 0)) {
             hdr_out->addEntry(e->clone());
         }
         break;
@@ -1756,8 +1751,7 @@
             hdr_out->addEntry(e->clone());
         } else {
             /** \note In accelerators, only forward authentication if enabled
-             * by login=PASS or login=PROXYPASS or login=PASSTHRU
-             * (see also below for proxy->server authentication)
+             * (see also httpFixupAuthentication for special cases)
              */
             if (orig_request->peer_login &&
                     (strcmp(orig_request->peer_login, "PASS") == 0 ||

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWdI0wpcABxnfgHQwc//////n
/vq////+YA08+Wtwu+91lgAAGxUNoUKK21mlMbVazTaszfDRUHqNNA0NAA0TARmgAAAQwAE0wamk
wJgphIAAaHqAAA0AAAAAHGTBNDIZGRk0NAGgyMIBoNGmQxDQARJIIKej0kzRNqaNMTU0yaGRiaGg
AAyaAPSCKRCZNCZPRGmp6npTaeUeSYapp5TTA1NAAABk0EkQTI0TJpop5Cek00npRk9Jk9EaGg0w
TQNBoMmAAYJgRJJBgFUlQGEyNnrp6rblTq5uuXWbGaQ4r2xaD7NtJUhzcvNzdrKbuft9zpXVuZMr
N67qZFSH2jGR6qgatasBatq56o+nWjZm9BJJkEUybdaklvaamAG42Pr12gM5JX4XGtI3UMvujefZ
w9eW/2lAe1rQkEkhAhCHa/Pw+awNn98/9bK9VuKxNuIHU4ZiOZLGokIQRAYm4sxPv/SaB6uRO1QF
QDIjOQkZClu/gTdvd58nPUtRGPgoOi7ms256Do9qjAqpPOdYT60hP5+evVzToBH1dvnO7Ffo5ORP
uTHsr34x0HMxMwJTaDm0PB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