]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ident/AclIdent.cc
Removed squid-old.h
[thirdparty/squid.git] / src / ident / AclIdent.cc
CommitLineData
8000a965 1/*
2 * $Id$
3 *
4 * DEBUG: section 28 Access Control
5 * AUTHOR: Duane Wessels
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
26ac0430 23 *
8000a965 24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
26ac0430 28 *
8000a965 29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 *
34 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
35 */
36
582c2af2 37#include "squid.h"
4daaf3cb
AJ
38
39#if USE_IDENT
40
127dce76
AR
41#include "acl/FilledChecklist.h"
42#include "acl/RegexData.h"
43#include "acl/UserData.h"
a46d2c0e 44#include "client_side.h"
f9b72e0c 45#include "comm/Connection.h"
582c2af2 46#include "globals.h"
4daaf3cb
AJ
47#include "ident/AclIdent.h"
48#include "ident/Ident.h"
8000a965 49
8000a965 50ACLIdent::~ACLIdent()
51{
00d77d6b 52 delete data;
3841dd46 53}
54
5dee515e 55ACLIdent::ACLIdent(ACLData<char const *> *newData, char const *newType) : data (newData), type_ (newType) {}
62e76326 56
3841dd46 57ACLIdent::ACLIdent (ACLIdent const &old) : data (old.data->clone()), type_ (old.type_)
62e76326 58{}
59
3841dd46 60ACLIdent &
61ACLIdent::operator= (ACLIdent const &rhs)
62{
63 data = rhs.data->clone();
64 type_ = rhs.type_;
65 return *this;
8000a965 66}
67
68char const *
69ACLIdent::typeString() const
70{
3841dd46 71 return type_;
8000a965 72}
73
74void
75ACLIdent::parse()
76{
1b0e74e5 77 if (!data) {
4daaf3cb 78 debugs(28, 3, HERE << "current is null. Creating");
1b0e74e5 79 data = new ACLUserData;
80 }
81
8000a965 82 data->parse();
83}
84
85int
127dce76 86ACLIdent::match(ACLChecklist *cl)
8000a965 87{
127dce76 88 ACLFilledChecklist *checklist = Filled(cl);
8000a965 89 if (checklist->rfc931[0]) {
62e76326 90 return data->match(checklist->rfc931);
73c36fd9
AJ
91 } else if (checklist->conn() != NULL && checklist->conn()->clientConnection != NULL && checklist->conn()->clientConnection->rfc931[0]) {
92 return data->match(checklist->conn()->clientConnection->rfc931);
e0f7153c 93 } else if (checklist->conn() != NULL && Comm::IsConnOpen(checklist->conn()->clientConnection)) {
4daaf3cb 94 debugs(28, 3, HERE << "switching to ident lookup state");
62e76326 95 checklist->changeState(IdentLookup::Instance());
96 return 0;
e0f7153c
AR
97 } else {
98 debugs(28, DBG_IMPORTANT, HERE << "Can't start ident lookup. No client connection" );
99 checklist->markFinished(ACCESS_DUNNO, "cannot start ident lookup");
100 return -1;
8000a965 101 }
102}
103
104wordlist *
105ACLIdent::dump() const
106{
107 return data->dump();
108}
109
110bool
4b0f5de8 111ACLIdent::empty () const
8000a965 112{
1bebfd93 113 return data->empty();
8000a965 114}
3841dd46 115
116ACL *
117ACLIdent::clone() const
118{
119 return new ACLIdent(*this);
120}
121
3841dd46 122
123IdentLookup IdentLookup::instance_;
124
125IdentLookup *
126IdentLookup::Instance()
127{
128 return &instance_;
129}
130
131void
127dce76 132IdentLookup::checkForAsync(ACLChecklist *cl)const
3841dd46 133{
127dce76 134 ACLFilledChecklist *checklist = Filled(cl);
e0f7153c
AR
135 const ConnStateData *conn = checklist->conn();
136 // check that ACLIdent::match() tested this lookup precondition
137 assert(conn && Comm::IsConnOpen(conn->clientConnection));
c0f81932
A
138 debugs(28, 3, HERE << "Doing ident lookup" );
139 checklist->asyncInProgress(true);
140 Ident::Start(checklist->conn()->clientConnection, LookupDone, checklist);
3841dd46 141}
142
143void
144IdentLookup::LookupDone(const char *ident, void *data)
145{
127dce76 146 ACLFilledChecklist *checklist = Filled(static_cast<ACLChecklist*>(data));
4daaf3cb 147 assert(checklist->asyncState() == IdentLookup::Instance());
3841dd46 148
149 if (ident) {
62e76326 150 xstrncpy(checklist->rfc931, ident, USER_IDENT_SZ);
3841dd46 151 } else {
62e76326 152 xstrncpy(checklist->rfc931, dash_str, USER_IDENT_SZ);
3841dd46 153 }
62e76326 154
3841dd46 155 /*
156 * Cache the ident result in the connection, to avoid redoing ident lookup
157 * over and over on persistent connections
158 */
73c36fd9
AJ
159 if (checklist->conn() != NULL && checklist->conn()->clientConnection != NULL && !checklist->conn()->clientConnection->rfc931[0])
160 xstrncpy(checklist->conn()->clientConnection->rfc931, checklist->rfc931, USER_IDENT_SZ);
62e76326 161
3841dd46 162 checklist->asyncInProgress(false);
4daaf3cb 163 checklist->changeState(ACLChecklist::NullState::Instance());
2efeb0b7 164 checklist->matchNonBlocking();
3841dd46 165}
4daaf3cb
AJ
166
167#endif /* USE_IDENT */