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

« back to all changes in this revision

Viewing changes to src/acl/Gadgets.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
 * This file contains ACL routines that are not part of the
 
8
 * ACL class, nor any other class yet, and that need to be
 
9
 * factored into appropriate places. They are here to reduce
 
10
 * unneeded dependencies between the ACL class and the rest
 
11
 * of squid.
 
12
 *
 
13
 * SQUID Web Proxy Cache          http://www.squid-cache.org/
 
14
 * ----------------------------------------------------------
 
15
 *
 
16
 *  Squid is the result of efforts by numerous individuals from
 
17
 *  the Internet community; see the CONTRIBUTORS file for full
 
18
 *  details.   Many organizations have provided support for Squid's
 
19
 *  development; see the SPONSORS file for full details.  Squid is
 
20
 *  Copyrighted (C) 2001 by the Regents of the University of
 
21
 *  California; see the COPYRIGHT file for full details.  Squid
 
22
 *  incorporates software developed and/or copyrighted by other
 
23
 *  sources; see the CREDITS file for full details.
 
24
 *
 
25
 *  This program is free software; you can redistribute it and/or modify
 
26
 *  it under the terms of the GNU General Public License as published by
 
27
 *  the Free Software Foundation; either version 2 of the License, or
 
28
 *  (at your option) any later version.
 
29
 *
 
30
 *  This program is distributed in the hope that it will be useful,
 
31
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
32
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
33
 *  GNU General Public License for more details.
 
34
 *
 
35
 *  You should have received a copy of the GNU General Public License
 
36
 *  along with this program; if not, write to the Free Software
 
37
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 
38
 *
 
39
 */
 
40
 
 
41
#include "squid.h"
 
42
#include "acl/Acl.h"
 
43
#include "acl/Checklist.h"
 
44
#include "acl/Strategised.h"
 
45
#include "acl/Gadgets.h"
 
46
#include "ConfigParser.h"
 
47
#include "errorpage.h"
 
48
#include "HttpRequest.h"
 
49
 
 
50
 
 
51
/* does name lookup, returns page_id */
 
52
err_type
 
53
aclGetDenyInfoPage(acl_deny_info_list ** head, const char *name, int redirect_allowed)
 
54
{
 
55
    acl_deny_info_list *A = NULL;
 
56
 
 
57
    debugs(28, 8, HERE << "got called for " << name);
 
58
 
 
59
    for (A = *head; A; A = A->next) {
 
60
        acl_name_list *L = NULL;
 
61
 
 
62
        if (!redirect_allowed && strchr(A->err_page_name, ':') ) {
 
63
            debugs(28, 8, HERE << "Skip '" << A->err_page_name << "' 30x redirects not allowed as response here.");
 
64
            continue;
 
65
        }
 
66
 
 
67
        for (L = A->acl_list; L; L = L->next) {
 
68
            if (!strcmp(name, L->name)) {
 
69
                debugs(28, 8, HERE << "match on " << name);
 
70
                return A->err_page_id;
 
71
            }
 
72
 
 
73
        }
 
74
    }
 
75
 
 
76
    debugs(28, 8, "aclGetDenyInfoPage: no match");
 
77
    return ERR_NONE;
 
78
}
 
79
 
 
80
/* does name lookup, returns if it is a proxy_auth acl */
 
81
int
 
82
aclIsProxyAuth(const char *name)
 
83
{
 
84
    debugs(28, 5, "aclIsProxyAuth: called for " << name);
 
85
 
 
86
    if (NULL == name)
 
87
        return false;
 
88
 
 
89
    ACL *a;
 
90
 
 
91
    if ((a = ACL::FindByName(name))) {
 
92
        debugs(28, 5, "aclIsProxyAuth: returning " << a->isProxyAuth());
 
93
        return a->isProxyAuth();
 
94
    }
 
95
 
 
96
    debugs(28, 3, "aclIsProxyAuth: WARNING, called for nonexistent ACL");
 
97
    return false;
 
98
}
 
99
 
 
100
 
 
101
/* maex@space.net (05.09.96)
 
102
 *    get the info for redirecting "access denied" to info pages
 
103
 *      TODO (probably ;-)
 
104
 *      currently there is no optimization for
 
105
 *      - more than one deny_info line with the same url
 
106
 *      - a check, whether the given acl really is defined
 
107
 *      - a check, whether an acl is added more than once for the same url
 
108
 */
 
109
 
 
110
void
 
111
aclParseDenyInfoLine(acl_deny_info_list ** head)
 
112
{
 
113
    char *t = NULL;
 
114
    acl_deny_info_list *A = NULL;
 
115
    acl_deny_info_list *B = NULL;
 
116
    acl_deny_info_list **T = NULL;
 
117
    acl_name_list *L = NULL;
 
118
    acl_name_list **Tail = NULL;
 
119
 
 
120
    /* first expect a page name */
 
121
 
 
122
    if ((t = strtok(NULL, w_space)) == NULL) {
 
123
        debugs(28, 0, "aclParseDenyInfoLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
 
124
        debugs(28, 0, "aclParseDenyInfoLine: missing 'error page' parameter.");
 
125
        return;
 
126
    }
 
127
 
 
128
    A = (acl_deny_info_list *)memAllocate(MEM_ACL_DENY_INFO_LIST);
 
129
    A->err_page_id = errorReservePageId(t);
 
130
    A->err_page_name = xstrdup(t);
 
131
    A->next = (acl_deny_info_list *) NULL;
 
132
    /* next expect a list of ACL names */
 
133
    Tail = &A->acl_list;
 
134
 
 
135
    while ((t = strtok(NULL, w_space))) {
 
136
        L = (acl_name_list *)memAllocate(MEM_ACL_NAME_LIST);
 
137
        xstrncpy(L->name, t, ACL_NAME_SZ);
 
138
        *Tail = L;
 
139
        Tail = &L->next;
 
140
    }
 
141
 
 
142
    if (A->acl_list == NULL) {
 
143
        debugs(28, 0, "aclParseDenyInfoLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
 
144
        debugs(28, 0, "aclParseDenyInfoLine: deny_info line contains no ACL's, skipping");
 
145
        memFree(A, MEM_ACL_DENY_INFO_LIST);
 
146
        return;
 
147
    }
 
148
 
 
149
    for (B = *head, T = head; B; T = &B->next, B = B->next)
 
150
 
 
151
        ;       /* find the tail */
 
152
    *T = A;
 
153
}
 
154
 
 
155
void
 
156
aclParseAccessLine(ConfigParser &parser, acl_access ** head)
 
157
{
 
158
    char *t = NULL;
 
159
    acl_access *A = NULL;
 
160
    acl_access *B = NULL;
 
161
    acl_access **T = NULL;
 
162
 
 
163
    /* first expect either 'allow' or 'deny' */
 
164
 
 
165
    if ((t = strtok(NULL, w_space)) == NULL) {
 
166
        debugs(28, 0, "aclParseAccessLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
 
167
        debugs(28, 0, "aclParseAccessLine: missing 'allow' or 'deny'.");
 
168
        return;
 
169
    }
 
170
 
 
171
    A = new acl_access;
 
172
 
 
173
    if (!strcmp(t, "allow"))
 
174
        A->allow = ACCESS_ALLOWED;
 
175
    else if (!strcmp(t, "deny"))
 
176
        A->allow = ACCESS_DENIED;
 
177
    else {
 
178
        debugs(28, 0, "aclParseAccessLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
 
179
        debugs(28, 0, "aclParseAccessLine: expecting 'allow' or 'deny', got '" << t << "'.");
 
180
        delete A;
 
181
        return;
 
182
    }
 
183
 
 
184
    aclParseAclList(parser, &A->aclList);
 
185
 
 
186
    if (A->aclList == NULL) {
 
187
        debugs(28, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
 
188
        debugs(28, 0, "aclParseAccessLine: Access line contains no ACL's, skipping");
 
189
        delete A;
 
190
        return;
 
191
    }
 
192
 
 
193
    A->cfgline = xstrdup(config_input_line);
 
194
    /* Append to the end of this list */
 
195
 
 
196
    for (B = *head, T = head; B; T = &B->next, B = B->next);
 
197
    *T = A;
 
198
 
 
199
    /* We lock _acl_access structures in ACLChecklist::check() */
 
200
}
 
201
 
 
202
void
 
203
aclParseAclList(ConfigParser &parser, ACLList ** head)
 
204
{
 
205
    ACLList **Tail = head;      /* sane name in the use below */
 
206
    ACL *a = NULL;
 
207
    char *t;
 
208
 
 
209
    /* next expect a list of ACL names, possibly preceeded
 
210
     * by '!' for negation */
 
211
 
 
212
    while ((t = strtok(NULL, w_space))) {
 
213
        ACLList *L = new ACLList;
 
214
 
 
215
        if (*t == '!') {
 
216
            L->negated (true);
 
217
            t++;
 
218
        }
 
219
 
 
220
        debugs(28, 3, "aclParseAclList: looking for ACL name '" << t << "'");
 
221
        a = ACL::FindByName(t);
 
222
 
 
223
        if (a == NULL) {
 
224
            debugs(28, 0, "aclParseAclList: ACL name '" << t << "' not found.");
 
225
            delete L;
 
226
            parser.destruct();
 
227
            continue;
 
228
        }
 
229
 
 
230
        L->_acl = a;
 
231
        *Tail = L;
 
232
        Tail = &L->next;
 
233
    }
 
234
}
 
235
 
 
236
 
 
237
 
 
238
/*********************/
 
239
/* Destroy functions */
 
240
/*********************/
 
241
 
 
242
void
 
243
aclDestroyAcls(ACL ** head)
 
244
{
 
245
    ACL *next = NULL;
 
246
 
 
247
    debugs(28, 8, "aclDestroyACLs: invoked");
 
248
 
 
249
    for (ACL *a = *head; a; a = next) {
 
250
        next = a->next;
 
251
        delete a;
 
252
    }
 
253
 
 
254
    *head = NULL;
 
255
}
 
256
 
 
257
void
 
258
aclDestroyAclList(ACLList ** head)
 
259
{
 
260
    ACLList *l;
 
261
    debugs(28, 8, "aclDestroyAclList: invoked");
 
262
 
 
263
    for (l = *head; l; l = *head) {
 
264
        *head = l->next;
 
265
        delete l;
 
266
    }
 
267
}
 
268
 
 
269
void
 
270
aclDestroyAccessList(acl_access ** list)
 
271
{
 
272
    acl_access *l = NULL;
 
273
    acl_access *next = NULL;
 
274
 
 
275
    for (l = *list; l; l = next) {
 
276
        debugs(28, 3, "aclDestroyAccessList: '" << l->cfgline << "'");
 
277
        next = l->next;
 
278
        aclDestroyAclList(&l->aclList);
 
279
        safe_free(l->cfgline);
 
280
        cbdataFree(l);
 
281
    }
 
282
 
 
283
    *list = NULL;
 
284
}
 
285
 
 
286
/* maex@space.net (06.09.1996)
 
287
 *    destroy an acl_deny_info_list */
 
288
 
 
289
void
 
290
aclDestroyDenyInfoList(acl_deny_info_list ** list)
 
291
{
 
292
    acl_deny_info_list *a = NULL;
 
293
    acl_deny_info_list *a_next = NULL;
 
294
    acl_name_list *l = NULL;
 
295
    acl_name_list *l_next = NULL;
 
296
 
 
297
    debugs(28, 8, "aclDestroyDenyInfoList: invoked");
 
298
 
 
299
    for (a = *list; a; a = a_next) {
 
300
        for (l = a->acl_list; l; l = l_next) {
 
301
            l_next = l->next;
 
302
            safe_free(l);
 
303
        }
 
304
 
 
305
        a_next = a->next;
 
306
        xfree(a->err_page_name);
 
307
        memFree(a, MEM_ACL_DENY_INFO_LIST);
 
308
    }
 
309
 
 
310
    *list = NULL;
 
311
}