]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4176: Digest auth too many helper lookups
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 8 Feb 2015 11:40:30 +0000 (03:40 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 8 Feb 2015 11:40:30 +0000 (03:40 -0800)
src/auth/User.cc
src/auth/User.h

index e90a1ea92ae8564b765f2a31724ba82c6084c307..48080993721c3cf011b11f7fb5859c9123a4e7bc 100644 (file)
@@ -309,7 +309,10 @@ SBuf
 Auth::User::BuildUserKey(const char *username, const char *realm)
 {
     SBuf key;
-    key.Printf("%s:%s", username, realm);
+    if (realm)
+        key.Printf("%s:%s", username, realm);
+    else
+        key.append(username, strlen(username));
     return key;
 }
 
@@ -365,10 +368,11 @@ Auth::User::username(char const *aString)
     if (aString) {
         assert(!username_);
         username_ = xstrdup(aString);
-        if (!requestRealm_.isEmpty())
-            userKey_ = BuildUserKey(username_, requestRealm_.c_str());
+        // NP: param #2 is working around a c_str() data-copy performance regression
+        userKey_ = BuildUserKey(username_, (!requestRealm_.isEmpty() ? requestRealm_.c_str() : NULL));
     } else {
         safe_free(username_);
+        userKey_.clear();
     }
 }
 
index 7ecdb2e90b7307529a719c14e363d3c4effb7d15..6af51cad1614b68f5d227f46d12fbdad17843a2e 100644 (file)
@@ -63,9 +63,10 @@ public:
     void absorb(Auth::User::Pointer from);
     virtual ~User();
     char const *username() const { return username_; }
-    void username(char const *);
+    void username(char const *); ///< set stored username and userKey
 
-    const char *userKey() {return !userKey_.isEmpty() ? userKey_.c_str() : username_;}
+    // NP: key is set at the same time as username_. Until then both are empty/NULL.
+    const char *userKey() {return !userKey_.isEmpty() ? userKey_.c_str() : NULL;}
 
     /**
      * How long these credentials are still valid for.