]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4679: User names not sent to url_rewrite_program (#78)
authorAmos Jeffries <yadij@users.noreply.github.com>
Fri, 3 Nov 2017 05:38:40 +0000 (18:38 +1300)
committerAmos Jeffries <yadij@users.noreply.github.com>
Tue, 9 Jan 2018 16:07:26 +0000 (05:07 +1300)
Add accessors to AccessLogEntry for retrieving IDENT and External ACL user
labels in a consistent way. Use these accessors for all log and logformat
outputs.

NP: does not hide/remove the original cache.* members due to direct use
    remaining in some code locations that cannot yet be avoided.

src/AccessLogEntry.cc
src/AccessLogEntry.h
src/client_side.cc
src/format/Format.cc
src/log/FormatHttpdCombined.cc
src/log/FormatHttpdCommon.cc
src/log/FormatSquidIcap.cc
src/log/FormatSquidNative.cc

index 09c2c83ce23363559b884bbf9731d1a68b47993c..25126e68b57503294537da710c4f6454a16a096e 100644 (file)
@@ -65,6 +65,30 @@ AccessLogEntry::getLogMethod() const
     return method;
 }
 
+const char *
+AccessLogEntry::getClientIdent() const
+{
+    if (tcpClient)
+        return tcpClient->rfc931;
+
+    if (cache.rfc931 && *cache.rfc931)
+        return cache.rfc931;
+
+    return nullptr;
+}
+
+const char *
+AccessLogEntry::getExtUser() const
+{
+    if (request && request->extacl_user.size())
+        return request->extacl_user.termedBuf();
+
+    if (cache.extuser && *cache.extuser)
+        return cache.extuser;
+
+    return nullptr;
+}
+
 AccessLogEntry::~AccessLogEntry()
 {
     safe_free(headers.request);
index 4a5c211126d6a72f6e4a959f2a9f344a1018fde4..41d909f739480c78b1e79f5153100f5847cdb946 100644 (file)
@@ -54,6 +54,12 @@ public:
     /// including indirect forwarded-for IP if configured to log that
     void getLogClientIp(char *buf, size_t bufsz) const;
 
+    /// Fetch the client IDENT string, or nil if none is available.
+    const char *getClientIdent() const;
+
+    /// Fetch the external ACL provided 'user=' string, or nil if none is available.
+    const char *getExtUser() const;
+
     /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
     SBuf getLogMethod() const;
 
index 55d10958b0f917c151ad60e6f3dd7d82002c6908..15a4e2bc10fd71be0f460d3c64a53587159ab66f 100644 (file)
@@ -415,9 +415,6 @@ ClientHttpRequest::logRequest()
     if (request)
         prepareLogWithRequestDetails(request, al);
 
-    if (getConn() != NULL && getConn()->clientConnection != NULL && getConn()->clientConnection->rfc931[0])
-        al->cache.rfc931 = getConn()->clientConnection->rfc931;
-
 #if USE_OPENSSL && 0
 
     /* This is broken. Fails if the connection has been closed. Needs
index 67c42de9d291211e0c01fdc3f4866270e9a5b57d..53bc708cb57e150dd592465d5f9b6a2e3562efe0 100644 (file)
@@ -873,13 +873,13 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS
                     out = t;
             }
             if (!out)
-                out = strOrNull(al->cache.extuser);
+                out = strOrNull(al->getExtUser());
 #if USE_OPENSSL
             if (!out)
                 out = strOrNull(al->cache.ssluser);
 #endif
             if (!out)
-                out = strOrNull(al->cache.rfc931);
+                out = strOrNull(al->getClientIdent());
             break;
 
         case LFT_USER_LOGIN:
@@ -890,17 +890,11 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS
             break;
 
         case LFT_USER_IDENT:
-            out = strOrNull(al->cache.rfc931);
+            out = strOrNull(al->getClientIdent());
             break;
 
         case LFT_USER_EXTERNAL:
-            if (al->request && al->request->extacl_user.size()) {
-                if (const char *t = al->request->extacl_user.termedBuf())
-                    out = t;
-            }
-
-            if (!out)
-                out = strOrNull(al->cache.extuser);
+            out = strOrNull(al->getExtUser());
             break;
 
         /* case LFT_USER_REALM: */
index 8db30f4dd470191cf4b67f74d42ef1aadec55033..61bb4a82471b3ac7961be043b304a92ca4070783 100644 (file)
@@ -22,7 +22,7 @@
 void
 Log::Format::HttpdCombined(const AccessLogEntry::Pointer &al, Logfile * logfile)
 {
-    const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931);
+    const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->getClientIdent());
     const char *user_auth = NULL;
     const char *referer = NULL;
     const char *agent = NULL;
index 40e3270b555c0bf31f9f5dab1d462a63428b5b9c..2f417cb308b5cd8ded325e59666e9b07cbdc444a 100644 (file)
@@ -27,7 +27,7 @@ Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile)
     if (al->request && al->request->auth_user_request != NULL)
         user_auth = ::Format::QuoteUrlEncodeUsername(al->request->auth_user_request->username());
 #endif
-    const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931);
+    const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->getClientIdent());
 
     char clientip[MAX_IPSTRLEN];
     al->getLogClientIp(clientip, MAX_IPSTRLEN);
index 969af779b2fbb0bc2fb29782292a597fe3a0c5ad..4257f310cd3627141e84b10ec3b4de324844f161 100644 (file)
@@ -43,7 +43,7 @@ Log::Format::SquidIcap(const AccessLogEntry::Pointer &al, Logfile * logfile)
 #endif
 
     if (!user)
-        user = ::Format::QuoteUrlEncodeUsername(al->cache.extuser);
+        user = ::Format::QuoteUrlEncodeUsername(al->getExtUser());
 
 #if USE_OPENSSL
     if (!user)
@@ -51,7 +51,7 @@ Log::Format::SquidIcap(const AccessLogEntry::Pointer &al, Logfile * logfile)
 #endif
 
     if (!user)
-        user = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931);
+        user = ::Format::QuoteUrlEncodeUsername(al->getClientIdent());
 
     if (user && !*user)
         safe_free(user);
index 628d4add804c3652b05fda74b9e9ac76256536ae..83a1b3e08dfa2f94473f0039454c3b9ef7ba0ab8 100644 (file)
@@ -32,7 +32,7 @@ Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile)
 #endif
 
     if (!user)
-        user = ::Format::QuoteUrlEncodeUsername(al->cache.extuser);
+        user = ::Format::QuoteUrlEncodeUsername(al->getExtUser());
 
 #if USE_OPENSSL
     if (!user)
@@ -40,7 +40,7 @@ Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile)
 #endif
 
     if (!user)
-        user = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931);
+        user = ::Format::QuoteUrlEncodeUsername(al->getClientIdent());
 
     if (user && !*user)
         safe_free(user);