]> 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)
committerGitHub <noreply@github.com>
Fri, 3 Nov 2017 05:38:40 +0000 (18:38 +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 b642a9953cb75a212f55ca902d23fca192463220..d5176e3881146c876c0e8ce827cc524bceff3b31 100644 (file)
@@ -70,6 +70,30 @@ AccessLogEntry::syncNotes(HttpRequest *req)
         assert(notes == req->notes());
 }
 
+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 616f02ef597c947697afe3750adfb1744af9f9ee..72dffd85d7651de956f942d7b8e4e675f98b456c 100644 (file)
@@ -49,6 +49,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 0e7c25a9171192c00c8eece1599d16ddaca5336f..02257c0521da401d5a88364d5d59096b52cac4b0 100644 (file)
@@ -416,9 +416,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 7e262fdc9fa3273994e870037d9ffc0a4ed51462..1f5edb145a0c2817d8ed4243e5606f895ad71e31 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 c4aad7851868e436d8eeefd234a36bdaacbfc699..cff3a1e596e5cfaff304d70c03474b43e870308b 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 2b66772f46b4a89e8b7d6477014f5f3580372635..c69502817b4c6689f648c54eccc3f4cddc5ea187 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 3fd3fcf71eca538c88ed3869a5941803941d78c8..dab7ae95e3ca2bad45862396c03597f73d1069d9 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 c4e2896c9411d5d3d6c64030120f339dfca16845..141398f9b259acc52d67bbcd5a3233448fe3a768 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);