]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Gadgets.cc
4 * DEBUG: section 28 Access Control
5 * AUTHOR: Duane Wessels
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
13 * SQUID Web Proxy Cache http://www.squid-cache.org/
14 * ----------------------------------------------------------
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.
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.
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.
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.
43 #include "acl/Checklist.h"
44 #include "acl/Strategised.h"
45 #include "acl/Gadgets.h"
46 #include "ConfigParser.h"
47 #include "errorpage.h"
49 #include "HttpRequest.h"
54 /* does name lookup, returns page_id */
56 aclGetDenyInfoPage(acl_deny_info_list
** head
, const char *name
, int redirect_allowed
)
58 acl_deny_info_list
*A
= NULL
;
60 debugs(28, 8, HERE
<< "got called for " << name
);
62 for (A
= *head
; A
; A
= A
->next
) {
63 acl_name_list
*L
= NULL
;
65 if (!redirect_allowed
&& strchr(A
->err_page_name
, ':') ) {
66 debugs(28, 8, HERE
<< "Skip '" << A
->err_page_name
<< "' 30x redirects not allowed as response here.");
70 for (L
= A
->acl_list
; L
; L
= L
->next
) {
71 if (!strcmp(name
, L
->name
)) {
72 debugs(28, 8, HERE
<< "match on " << name
);
73 return A
->err_page_id
;
79 debugs(28, 8, "aclGetDenyInfoPage: no match");
83 /* does name lookup, returns if it is a proxy_auth acl */
85 aclIsProxyAuth(const char *name
)
87 debugs(28, 5, "aclIsProxyAuth: called for " << name
);
94 if ((a
= ACL::FindByName(name
))) {
95 debugs(28, 5, "aclIsProxyAuth: returning " << a
->isProxyAuth());
96 return a
->isProxyAuth();
99 debugs(28, 3, "aclIsProxyAuth: WARNING, called for nonexistent ACL");
104 /* maex@space.net (05.09.96)
105 * get the info for redirecting "access denied" to info pages
107 * currently there is no optimization for
108 * - more than one deny_info line with the same url
109 * - a check, whether the given acl really is defined
110 * - a check, whether an acl is added more than once for the same url
114 aclParseDenyInfoLine(acl_deny_info_list
** head
)
117 acl_deny_info_list
*A
= NULL
;
118 acl_deny_info_list
*B
= NULL
;
119 acl_deny_info_list
**T
= NULL
;
120 acl_name_list
*L
= NULL
;
121 acl_name_list
**Tail
= NULL
;
123 /* first expect a page name */
125 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
126 debugs(28, DBG_CRITICAL
, "aclParseDenyInfoLine: " << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
127 debugs(28, DBG_CRITICAL
, "aclParseDenyInfoLine: missing 'error page' parameter.");
131 A
= (acl_deny_info_list
*)memAllocate(MEM_ACL_DENY_INFO_LIST
);
132 A
->err_page_id
= errorReservePageId(t
);
133 A
->err_page_name
= xstrdup(t
);
134 A
->next
= (acl_deny_info_list
*) NULL
;
135 /* next expect a list of ACL names */
138 while ((t
= strtok(NULL
, w_space
))) {
139 L
= (acl_name_list
*)memAllocate(MEM_ACL_NAME_LIST
);
140 xstrncpy(L
->name
, t
, ACL_NAME_SZ
);
145 if (A
->acl_list
== NULL
) {
146 debugs(28, DBG_CRITICAL
, "aclParseDenyInfoLine: " << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
147 debugs(28, DBG_CRITICAL
, "aclParseDenyInfoLine: deny_info line contains no ACL's, skipping");
148 memFree(A
, MEM_ACL_DENY_INFO_LIST
);
152 for (B
= *head
, T
= head
; B
; T
= &B
->next
, B
= B
->next
)
154 ; /* find the tail */
159 aclParseAccessLine(ConfigParser
&parser
, acl_access
** head
)
162 acl_access
*A
= NULL
;
163 acl_access
*B
= NULL
;
164 acl_access
**T
= NULL
;
166 /* first expect either 'allow' or 'deny' */
168 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
169 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: " << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
170 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: missing 'allow' or 'deny'.");
176 if (!strcmp(t
, "allow"))
177 A
->allow
= ACCESS_ALLOWED
;
178 else if (!strcmp(t
, "deny"))
179 A
->allow
= ACCESS_DENIED
;
181 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: " << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
182 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: expecting 'allow' or 'deny', got '" << t
<< "'.");
187 aclParseAclList(parser
, &A
->aclList
);
189 if (A
->aclList
== NULL
) {
190 debugs(28, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
191 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: Access line contains no ACL's, skipping");
196 A
->cfgline
= xstrdup(config_input_line
);
197 /* Append to the end of this list */
199 for (B
= *head
, T
= head
; B
; T
= &B
->next
, B
= B
->next
);
202 /* We lock _acl_access structures in ACLChecklist::matchNonBlocking() */
206 aclParseAclList(ConfigParser
&parser
, ACLList
** head
)
208 ACLList
**Tail
= head
; /* sane name in the use below */
212 /* next expect a list of ACL names, possibly preceeded
213 * by '!' for negation */
215 while ((t
= strtok(NULL
, w_space
))) {
216 ACLList
*L
= new ACLList
;
223 debugs(28, 3, "aclParseAclList: looking for ACL name '" << t
<< "'");
224 a
= ACL::FindByName(t
);
227 debugs(28, DBG_CRITICAL
, "aclParseAclList: ACL name '" << t
<< "' not found.");
241 /*********************/
242 /* Destroy functions */
243 /*********************/
246 aclDestroyAcls(ACL
** head
)
250 debugs(28, 8, "aclDestroyACLs: invoked");
252 for (ACL
*a
= *head
; a
; a
= next
) {
261 aclDestroyAclList(ACLList
** head
)
264 debugs(28, 8, "aclDestroyAclList: invoked");
266 for (l
= *head
; l
; l
= *head
) {
273 aclDestroyAccessList(acl_access
** list
)
275 acl_access
*l
= NULL
;
276 acl_access
*next
= NULL
;
278 for (l
= *list
; l
; l
= next
) {
279 debugs(28, 3, "aclDestroyAccessList: '" << l
->cfgline
<< "'");
281 aclDestroyAclList(&l
->aclList
);
282 safe_free(l
->cfgline
);
289 /* maex@space.net (06.09.1996)
290 * destroy an acl_deny_info_list */
293 aclDestroyDenyInfoList(acl_deny_info_list
** list
)
295 acl_deny_info_list
*a
= NULL
;
296 acl_deny_info_list
*a_next
= NULL
;
297 acl_name_list
*l
= NULL
;
298 acl_name_list
*l_next
= NULL
;
300 debugs(28, 8, "aclDestroyDenyInfoList: invoked");
302 for (a
= *list
; a
; a
= a_next
) {
303 for (l
= a
->acl_list
; l
; l
= l_next
) {
309 xfree(a
->err_page_name
);
310 memFree(a
, MEM_ACL_DENY_INFO_LIST
);