AclIdent.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
30 ACLIdent::ACLIdent(ACLData<char const *> *newData, char const *newType) : data (newData), type_ (newType) {}
31 
32 ACLIdent::ACLIdent (ACLIdent const &old) : data (old.data->clone()), type_ (old.type_)
33 {}
34 
35 ACLIdent &
37 {
38  data = rhs.data->clone();
39  type_ = rhs.type_;
40  return *this;
41 }
42 
43 char const *
45 {
46  return type_;
47 }
48 
49 void
51 {
53 }
54 
55 void
57 {
58  if (!data) {
59  debugs(28, 3, HERE << "current is null. Creating");
60  data = new ACLUserData;
61  }
62 
63  data->parse();
64 }
65 
66 int
68 {
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");
77  return -1;
78  }
79  // else fall through to ACCESS_DUNNO failure below
80  } else {
81  debugs(28, DBG_IMPORTANT, HERE << "Can't start ident lookup. No client connection" );
82  // fall through to ACCESS_DUNNO failure below
83  }
84 
85  checklist->markFinished(ACCESS_DUNNO, "cannot start ident lookup");
86  return -1;
87 }
88 
91 {
92  return data->dump();
93 }
94 
95 bool
97 {
98  return data->empty();
99 }
100 
101 ACL *
103 {
104  return new ACLIdent(*this);
105 }
106 
108 
109 IdentLookup *
111 {
112  return &instance_;
113 }
114 
115 void
117 {
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);
124 }
125 
126 void
127 IdentLookup::LookupDone(const char *ident, void *data)
128 {
129  ACLFilledChecklist *checklist = Filled(static_cast<ACLChecklist*>(data));
130 
131  if (ident) {
132  xstrncpy(checklist->rfc931, ident, USER_IDENT_SZ);
133  } else {
134  xstrncpy(checklist->rfc931, dash_str, USER_IDENT_SZ);
135  }
136 
137  /*
138  * Cache the ident result in the connection, to avoid redoing ident lookup
139  * over and over on persistent connections
140  */
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);
143 
145 }
146 
147 #endif /* USE_IDENT */
148 
virtual bool empty() const =0
static void LookupDone(const char *ident, void *data)
Definition: AclIdent.cc:127
#define assert(EX)
Definition: assert.h:17
virtual bool match(M)=0
ACLIdent(ACLData< char const * > *newData, char const *)
Definition: AclIdent.cc:30
virtual void checkForAsync(ACLChecklist *) const
Definition: AclIdent.cc:116
virtual char const * typeString() const
Definition: AclIdent.cc:44
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
virtual const Acl::ParameterFlags & supportedFlags() const
Definition: Data.h:25
Definition: Acl.h:39
int conn
the current server connection FD
Definition: Transport.cc:26
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
Definition: AclIdent.cc:67
ConnStateData * conn() const
The client connection manager.
static IdentLookup * Instance()
Definition: AclIdent.cc:110
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:24
void const char HLPCB void * data
Definition: stub_helper.cc:16
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
bool goAsync(AsyncState *)
Definition: Checklist.cc:115
#define DBG_IMPORTANT
Definition: Debug.h:45
#define USER_IDENT_SZ
Definition: defines.h:60
void ParseFlags(const Options &options, const ParameterFlags &flags)
Definition: Options.cc:240
char * xstrncpy(char *dst, const char *src, size_t n)
Definition: xstring.cc:37
virtual void parse()=0
~ACLIdent()
Definition: AclIdent.cc:25
char rfc931[USER_IDENT_SZ]
void markFinished(const allow_t &newAnswer, const char *reason)
Definition: Checklist.cc:58
std::list< SBuf > SBufList
Definition: forward.h:26
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
char rfc931[USER_IDENT_SZ]
Definition: Connection.h:155
void resumeNonBlockingCheck(AsyncState *state)
Definition: Checklist.cc:262
virtual ACL * clone() const
Definition: AclIdent.cc:102
virtual void parse()
parses node represenation in squid.conf; dies on failures
Definition: AclIdent.cc:56
ACLIdent & operator=(ACLIdent const &rhs)
Definition: AclIdent.cc:36
Comm::ConnectionPointer clientConnection
Definition: Server.h:97
virtual SBufList dump() const =0
virtual SBufList dump() const
Definition: AclIdent.cc:90
char const * type_
Definition: AclIdent.h:55
ACLData< char const * > * data
Definition: AclIdent.h:54
static IdentLookup instance_
Definition: AclIdent.h:25
virtual ACLData * clone() const =0
virtual void parseFlags()
configures ACL options, throwing on configuration errors
Definition: AclIdent.cc:50
const Options & NoOptions()
Definition: Options.cc:247
#define NULL
Definition: types.h:166
void Start(const Comm::ConnectionPointer &conn, IDCB *callback, void *cbdata)
Definition: Ident.cc:237
virtual bool empty() const
Definition: AclIdent.cc:96
const char * dash_str

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors