AclIdent.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 28 Access Control */
10
11#include "squid.h"
12
13#if USE_IDENT
14
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"
20#include "globals.h"
21#include "http/Stream.h"
22#include "ident/AclIdent.h"
23#include "ident/Ident.h"
24
26{
27 delete data;
28}
29
30ACLIdent::ACLIdent(ACLData<char const *> *newData, char const *newType) : data (newData), type_ (newType) {}
31
32char const *
34{
35 return type_;
36}
37
38const Acl::Options &
40{
41 return data->lineOptions();
42}
43
44void
46{
47 if (!data) {
48 debugs(28, 3, "current is null. Creating");
49 data = new ACLUserData;
50 }
51
52 data->parse();
53}
54
55int
57{
58 ACLFilledChecklist *checklist = Filled(cl);
59 if (checklist->rfc931[0]) {
60 return data->match(checklist->rfc931);
61 } else if (checklist->conn() != nullptr && checklist->conn()->clientConnection != nullptr && checklist->conn()->clientConnection->rfc931[0]) {
62 return data->match(checklist->conn()->clientConnection->rfc931);
63 } else if (checklist->conn() != nullptr && Comm::IsConnOpen(checklist->conn()->clientConnection)) {
64 if (checklist->goAsync(IdentLookup::Instance())) {
65 debugs(28, 3, "switching to ident lookup state");
66 return -1;
67 }
68 // else fall through to ACCESS_DUNNO failure below
69 } else {
70 debugs(28, DBG_IMPORTANT, "ERROR: Cannot start ident lookup. No client connection" );
71 // fall through to ACCESS_DUNNO failure below
72 }
73
74 checklist->markFinished(ACCESS_DUNNO, "cannot start ident lookup");
75 return -1;
76}
77
80{
81 return data->dump();
82}
83
84bool
86{
87 return data->empty();
88}
89
91
94{
95 return &instance_;
96}
97
98void
100{
101 ACLFilledChecklist *checklist = Filled(cl);
102 const ConnStateData *conn = checklist->conn();
103 // check that ACLIdent::match() tested this lookup precondition
104 assert(conn && Comm::IsConnOpen(conn->clientConnection));
105 debugs(28, 3, "Doing ident lookup" );
106 Ident::Start(checklist->conn()->clientConnection, LookupDone, checklist);
107}
108
109void
110IdentLookup::LookupDone(const char *ident, void *data)
111{
112 ACLFilledChecklist *checklist = Filled(static_cast<ACLChecklist*>(data));
113
114 if (ident) {
115 xstrncpy(checklist->rfc931, ident, USER_IDENT_SZ);
116 } else {
118 }
119
120 /*
121 * Cache the ident result in the connection, to avoid redoing ident lookup
122 * over and over on persistent connections
123 */
124 if (checklist->conn() != nullptr && checklist->conn()->clientConnection != nullptr && !checklist->conn()->clientConnection->rfc931[0])
125 xstrncpy(checklist->conn()->clientConnection->rfc931, checklist->rfc931, USER_IDENT_SZ);
126
128}
129
130#endif /* USE_IDENT */
131
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:17
void markFinished(const Acl::Answer &newAnswer, const char *reason)
Definition: Checklist.cc:57
bool goAsync(AsyncState *)
Definition: Checklist.cc:114
void resumeNonBlockingCheck(AsyncState *state)
Definition: Checklist.cc:261
virtual void parse()=0
virtual SBufList dump() const =0
virtual bool match(M)=0
virtual bool empty() const =0
virtual const Acl::Options & lineOptions()
supported ACL "line" options (e.g., "-i")
Definition: Data.h:26
ConnStateData * conn() const
The client connection manager.
char rfc931[USER_IDENT_SZ]
bool empty() const override
Definition: AclIdent.cc:85
char const * type_
Definition: AclIdent.h:54
char const * typeString() const override
Definition: AclIdent.cc:33
~ACLIdent() override
Definition: AclIdent.cc:25
SBufList dump() const override
Definition: AclIdent.cc:79
ACLData< char const * > * data
Definition: AclIdent.h:53
int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this ACL.
Definition: AclIdent.cc:56
ACLIdent(ACLData< char const * > *newData, char const *)
Definition: AclIdent.cc:30
const Acl::Options & lineOptions() override
Definition: AclIdent.cc:39
void parse() override
parses node representation in squid.conf; dies on failures
Definition: AclIdent.cc:45
char rfc931[USER_IDENT_SZ]
Definition: Connection.h:176
static void LookupDone(const char *ident, void *data)
Definition: AclIdent.cc:110
static IdentLookup * Instance()
Definition: AclIdent.cc:93
static IdentLookup instance_
Definition: AclIdent.h:25
void checkForAsync(ACLChecklist *) const override
Definition: AclIdent.cc:99
Comm::ConnectionPointer clientConnection
Definition: Server.h:100
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define USER_IDENT_SZ
Definition: defines.h:37
const char * dash_str
@ ACCESS_DUNNO
Definition: Acl.h:117
std::vector< const Option * > Options
Definition: Options.h:214
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:27
void Start(const Comm::ConnectionPointer &conn, IDCB *callback, void *cbdata)
Definition: Ident.cc:264
std::list< SBuf > SBufList
Definition: forward.h:23
char * xstrncpy(char *dst, const char *src, size_t n)
Definition: xstring.cc:37

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors