]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ident/AclIdent.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ident / AclIdent.cc
index aa9ecc6b9624e5d865f41a31ac9a3d1c290dd8c4..34c00fdc30f3f8a70cb88dfb32c346932944ddc3 100644 (file)
@@ -43,6 +43,7 @@
 #include "acl/UserData.h"
 #include "client_side.h"
 #include "comm/Connection.h"
+#include "globals.h"
 #include "ident/AclIdent.h"
 #include "ident/Ident.h"
 
@@ -87,12 +88,16 @@ ACLIdent::match(ACLChecklist *cl)
     ACLFilledChecklist *checklist = Filled(cl);
     if (checklist->rfc931[0]) {
         return data->match(checklist->rfc931);
-    } else if (checklist->conn() != NULL && checklist->conn()->rfc931[0]) {
-        return data->match(checklist->conn()->rfc931);
-    } else {
+    } else if (checklist->conn() != NULL && checklist->conn()->clientConnection != NULL && checklist->conn()->clientConnection->rfc931[0]) {
+        return data->match(checklist->conn()->clientConnection->rfc931);
+    } else if (checklist->conn() != NULL && Comm::IsConnOpen(checklist->conn()->clientConnection)) {
         debugs(28, 3, HERE << "switching to ident lookup state");
         checklist->changeState(IdentLookup::Instance());
         return 0;
+    } else {
+        debugs(28, DBG_IMPORTANT, HERE << "Can't start ident lookup. No client connection" );
+        checklist->markFinished(ACCESS_DUNNO, "cannot start ident lookup");
+        return -1;
     }
 }
 
@@ -114,7 +119,6 @@ ACLIdent::clone() const
     return new ACLIdent(*this);
 }
 
-
 IdentLookup IdentLookup::instance_;
 
 IdentLookup *
@@ -127,20 +131,12 @@ void
 IdentLookup::checkForAsync(ACLChecklist *cl)const
 {
     ACLFilledChecklist *checklist = Filled(cl);
-    if (checklist->conn() != NULL) {
-        debugs(28, 3, HERE << "Doing ident lookup" );
-        checklist->asyncInProgress(true);
-        // TODO: store a Comm::Connection in either checklist or ConnStateData one day.
-        Comm::Connection cc; // IDENT will clone it's own copy for alterations.
-        cc.local = checklist->conn()->me;
-        cc.remote = checklist->conn()->peer;
-        Comm::ConnectionPointer ccp = &cc;
-        Ident::Start(ccp, LookupDone, checklist);
-    } else {
-        debugs(28, DBG_IMPORTANT, "IdentLookup::checkForAsync: Can't start ident lookup. No client connection" );
-        checklist->currentAnswer(ACCESS_DENIED);
-        checklist->markFinished();
-    }
+    const ConnStateData *conn = checklist->conn();
+    // check that ACLIdent::match() tested this lookup precondition
+    assert(conn && Comm::IsConnOpen(conn->clientConnection));
+    debugs(28, 3, HERE << "Doing ident lookup" );
+    checklist->asyncInProgress(true);
+    Ident::Start(checklist->conn()->clientConnection, LookupDone, checklist);
 }
 
 void
@@ -159,12 +155,12 @@ IdentLookup::LookupDone(const char *ident, void *data)
      * Cache the ident result in the connection, to avoid redoing ident lookup
      * over and over on persistent connections
      */
-    if (checklist->conn() != NULL && !checklist->conn()->rfc931[0])
-        xstrncpy(checklist->conn()->rfc931, checklist->rfc931, USER_IDENT_SZ);
+    if (checklist->conn() != NULL && checklist->conn()->clientConnection != NULL && !checklist->conn()->clientConnection->rfc931[0])
+        xstrncpy(checklist->conn()->clientConnection->rfc931, checklist->rfc931, USER_IDENT_SZ);
 
     checklist->asyncInProgress(false);
     checklist->changeState(ACLChecklist::NullState::Instance());
-    checklist->check();
+    checklist->matchNonBlocking();
 }
 
 #endif /* USE_IDENT */