]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ident/AclIdent.cc
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 28 Access Control */
15 #include "acl/FilledChecklist.h"
16 #include "acl/RegexData.h"
17 #include "acl/UserData.h"
18 #include "client_side.h"
19 #include "comm/Connection.h"
21 #include "http/Stream.h"
22 #include "ident/AclIdent.h"
23 #include "ident/Ident.h"
30 ACLIdent::ACLIdent(ACLData
<char const *> *newData
, char const *newType
) : data (newData
), type_ (newType
) {}
32 ACLIdent::ACLIdent (ACLIdent
const &old
) : data (old
.data
->clone()), type_ (old
.type_
)
36 ACLIdent::operator= (ACLIdent
const &rhs
)
38 data
= rhs
.data
->clone();
44 ACLIdent::typeString() const
50 ACLIdent::parseFlags()
52 ParseFlags(Acl::NoOptions(), data
->supportedFlags());
59 debugs(28, 3, HERE
<< "current is null. Creating");
60 data
= new ACLUserData
;
67 ACLIdent::match(ACLChecklist
*cl
)
69 ACLFilledChecklist
*checklist
= Filled(cl
);
70 if (checklist
->rfc931
[0]) {
71 return data
->match(checklist
->rfc931
);
72 } else if (checklist
->conn() != NULL
&& checklist
->conn()->clientConnection
!= NULL
&& checklist
->conn()->clientConnection
->rfc931
[0]) {
73 return data
->match(checklist
->conn()->clientConnection
->rfc931
);
74 } else if (checklist
->conn() != NULL
&& Comm::IsConnOpen(checklist
->conn()->clientConnection
)) {
75 if (checklist
->goAsync(IdentLookup::Instance())) {
76 debugs(28, 3, "switching to ident lookup state");
79 // else fall through to ACCESS_DUNNO failure below
81 debugs(28, DBG_IMPORTANT
, HERE
<< "Can't start ident lookup. No client connection" );
82 // fall through to ACCESS_DUNNO failure below
85 checklist
->markFinished(ACCESS_DUNNO
, "cannot start ident lookup");
90 ACLIdent::dump() const
96 ACLIdent::empty () const
102 ACLIdent::clone() const
104 return new ACLIdent(*this);
107 IdentLookup
IdentLookup::instance_
;
110 IdentLookup::Instance()
116 IdentLookup::checkForAsync(ACLChecklist
*cl
)const
118 ACLFilledChecklist
*checklist
= Filled(cl
);
119 const ConnStateData
*conn
= checklist
->conn();
120 // check that ACLIdent::match() tested this lookup precondition
121 assert(conn
&& Comm::IsConnOpen(conn
->clientConnection
));
122 debugs(28, 3, HERE
<< "Doing ident lookup" );
123 Ident::Start(checklist
->conn()->clientConnection
, LookupDone
, checklist
);
127 IdentLookup::LookupDone(const char *ident
, void *data
)
129 ACLFilledChecklist
*checklist
= Filled(static_cast<ACLChecklist
*>(data
));
132 xstrncpy(checklist
->rfc931
, ident
, USER_IDENT_SZ
);
134 xstrncpy(checklist
->rfc931
, dash_str
, USER_IDENT_SZ
);
138 * Cache the ident result in the connection, to avoid redoing ident lookup
139 * over and over on persistent connections
141 if (checklist
->conn() != NULL
&& checklist
->conn()->clientConnection
!= NULL
&& !checklist
->conn()->clientConnection
->rfc931
[0])
142 xstrncpy(checklist
->conn()->clientConnection
->rfc931
, checklist
->rfc931
, USER_IDENT_SZ
);
144 checklist
->resumeNonBlockingCheck(IdentLookup::Instance());
147 #endif /* USE_IDENT */