~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/ACLProxyAuth.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
23
 
 *  
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.
28
 
 *  
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
 
 
37
 
#include "squid.h"
38
 
#include "ACLProxyAuth.h"
39
 
#include "authenticate.h"
40
 
#include "ACLChecklist.h"
41
 
#include "ACLUserData.h"
42
 
#include "ACLRegexData.h"
43
 
#include "client_side.h"
44
 
#include "HttpRequest.h"
45
 
#include "AuthUser.h"
46
 
#include "AuthUserRequest.h"
47
 
 
48
 
ACLProxyAuth::~ACLProxyAuth()
49
 
{
50
 
    delete data;
51
 
}
52
 
 
53
 
ACLProxyAuth::ACLProxyAuth(ACLData<char const *> *newData, char const *theType) : data (newData), type_(theType) {}
54
 
 
55
 
ACLProxyAuth::ACLProxyAuth (ACLProxyAuth const &old) : data (old.data->clone()), type_(old.type_)
56
 
{}
57
 
 
58
 
ACLProxyAuth &
59
 
ACLProxyAuth::operator= (ACLProxyAuth const &rhs)
60
 
{
61
 
    data = rhs.data->clone();
62
 
    type_ = rhs.type_;
63
 
    return *this;
64
 
}
65
 
 
66
 
char const *
67
 
ACLProxyAuth::typeString() const
68
 
{
69
 
    return type_;
70
 
}
71
 
 
72
 
void
73
 
ACLProxyAuth::parse()
74
 
{
75
 
    data->parse();
76
 
}
77
 
 
78
 
int
79
 
ACLProxyAuth::match(ACLChecklist *checklist)
80
 
{
81
 
    int ti;
82
 
 
83
 
    if ((ti = checklist->authenticated()) != 1)
84
 
        return ti;
85
 
 
86
 
    ti = matchProxyAuth(checklist);
87
 
 
88
 
    return ti;
89
 
}
90
 
 
91
 
wordlist *
92
 
ACLProxyAuth::dump() const
93
 
{
94
 
    return data->dump();
95
 
}
96
 
 
97
 
bool
98
 
ACLProxyAuth::empty () const
99
 
{
100
 
    return data->empty();
101
 
}
102
 
 
103
 
bool
104
 
ACLProxyAuth::valid () const
105
 
{
106
 
    if (authenticateSchemeCount() == 0) {
107
 
        debugs(28, 0, "Can't use proxy auth because no authentication schemes were compiled.");
108
 
        return false;
109
 
    }
110
 
 
111
 
    if (authenticateActiveSchemeCount() == 0) {
112
 
        debugs(28, 0, "Can't use proxy auth because no authentication schemes are fully configured.");
113
 
        return false;
114
 
    }
115
 
 
116
 
    return true;
117
 
}
118
 
 
119
 
ProxyAuthNeeded ProxyAuthNeeded::instance_;
120
 
 
121
 
ProxyAuthNeeded *
122
 
ProxyAuthNeeded::Instance()
123
 
{
124
 
    return &instance_;
125
 
}
126
 
 
127
 
ProxyAuthLookup ProxyAuthLookup::instance_;
128
 
 
129
 
ProxyAuthLookup *
130
 
ProxyAuthLookup::Instance()
131
 
{
132
 
    return &instance_;
133
 
}
134
 
 
135
 
void
136
 
ProxyAuthLookup::checkForAsync(ACLChecklist *checklist)const
137
 
{
138
 
    checklist->asyncInProgress(true);
139
 
    debugs(28, 3, "ACLChecklist::checkForAsync: checking password via authenticator");
140
 
 
141
 
    AuthUserRequest *auth_user_request;
142
 
    /* make sure someone created auth_user_request for us */
143
 
    assert(checklist->auth_user_request != NULL);
144
 
    auth_user_request = checklist->auth_user_request;
145
 
 
146
 
    assert(authenticateValidateUser(auth_user_request));
147
 
    auth_user_request->start(LookupDone, checklist);
148
 
}
149
 
 
150
 
void
151
 
ProxyAuthLookup::LookupDone(void *data, char *result)
152
 
{
153
 
    ACLChecklist *checklist = (ACLChecklist *)data;
154
 
    assert (checklist->asyncState() == ProxyAuthLookup::Instance());
155
 
 
156
 
    if (result != NULL)
157
 
        fatal("AclLookupProxyAuthDone: Old code floating around somewhere.\nMake clean and if that doesn't work, report a bug to the squid developers.\n");
158
 
 
159
 
    if (!authenticateValidateUser(checklist->auth_user_request) || checklist->conn() == NULL) {
160
 
        /* credentials could not be checked either way
161
 
         * restart the whole process */
162
 
        /* OR the connection was closed, there's no way to continue */
163
 
        AUTHUSERREQUESTUNLOCK(checklist->auth_user_request, "ProxyAuthLookup");
164
 
 
165
 
        if (checklist->conn() != NULL) {
166
 
            AUTHUSERREQUESTUNLOCK(checklist->conn()->auth_user_request, "conn via ProxyAuthLookup");    // DPW discomfort
167
 
            checklist->conn()->auth_type = AUTH_BROKEN;
168
 
        }
169
 
    }
170
 
 
171
 
    checklist->asyncInProgress(false);
172
 
    checklist->changeState (ACLChecklist::NullState::Instance());
173
 
    checklist->check();
174
 
}
175
 
 
176
 
void
177
 
ProxyAuthNeeded::checkForAsync(ACLChecklist *checklist) const
178
 
{
179
 
    /* Client is required to resend the request with correct authentication
180
 
     * credentials. (This may be part of a stateful auth protocol.)
181
 
     * The request is denied.
182
 
     */
183
 
    debugs(28, 6, "ACLChecklist::checkForAsync: requiring Proxy Auth header.");
184
 
    checklist->currentAnswer(ACCESS_REQ_PROXY_AUTH);
185
 
    checklist->changeState (ACLChecklist::NullState::Instance());
186
 
    checklist->markFinished();
187
 
}
188
 
 
189
 
ACL::Prototype ACLProxyAuth::UserRegistryProtoype(&ACLProxyAuth::UserRegistryEntry_, "proxy_auth");
190
 
ACLProxyAuth ACLProxyAuth::UserRegistryEntry_(new ACLUserData, "proxy_auth");
191
 
ACL::Prototype ACLProxyAuth::RegexRegistryProtoype(&ACLProxyAuth::RegexRegistryEntry_, "proxy_auth_regex" );
192
 
ACLProxyAuth ACLProxyAuth::RegexRegistryEntry_(new ACLRegexData, "proxy_auth_regex");
193
 
 
194
 
ACL *
195
 
ACLProxyAuth::clone() const
196
 
{
197
 
    return new ACLProxyAuth(*this);
198
 
}
199
 
 
200
 
int
201
 
ACLProxyAuth::matchForCache(ACLChecklist *checklist)
202
 
{
203
 
    assert (checklist->auth_user_request);
204
 
    return data->match(checklist->auth_user_request->username());
205
 
}
206
 
 
207
 
/* aclMatchProxyAuth can return two exit codes:
208
 
 * 0 : Authorisation for this ACL failed. (Did not match)
209
 
 * 1 : Authorisation OK. (Matched)
210
 
 */
211
 
int
212
 
ACLProxyAuth::matchProxyAuth(ACLChecklist *checklist)
213
 
{
214
 
    checkAuthForCaching(checklist);
215
 
    /* check to see if we have matched the user-acl before */
216
 
    int result = cacheMatchAcl(&checklist->auth_user_request->user()->
217
 
                               proxy_match_cache, checklist);
218
 
    AUTHUSERREQUESTUNLOCK(checklist->auth_user_request, "ACLChecklist via ACLProxyAuth");
219
 
    return result;
220
 
}
221
 
 
222
 
void
223
 
ACLProxyAuth::checkAuthForCaching(ACLChecklist *checklist)const
224
 
{
225
 
    /* for completeness */
226
 
    /* consistent parameters ? */
227
 
    assert(authenticateUserAuthenticated(checklist->auth_user_request));
228
 
    /* this check completed */
229
 
}
230