]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Gadgets.cc
2 * DEBUG: section 28 Access Control
3 * AUTHOR: Duane Wessels
5 * This file contains ACL routines that are not part of the
6 * ACL class, nor any other class yet, and that need to be
7 * factored into appropriate places. They are here to reduce
8 * unneeded dependencies between the ACL class and the rest
11 * SQUID Web Proxy Cache http://www.squid-cache.org/
12 * ----------------------------------------------------------
14 * Squid is the result of efforts by numerous individuals from
15 * the Internet community; see the CONTRIBUTORS file for full
16 * details. Many organizations have provided support for Squid's
17 * development; see the SPONSORS file for full details. Squid is
18 * Copyrighted (C) 2001 by the Regents of the University of
19 * California; see the COPYRIGHT file for full details. Squid
20 * incorporates software developed and/or copyrighted by other
21 * sources; see the CREDITS file for full details.
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
41 #include "acl/Checklist.h"
42 #include "acl/Strategised.h"
43 #include "acl/Gadgets.h"
44 #include "ConfigParser.h"
45 #include "errorpage.h"
47 #include "HttpRequest.h"
50 /* does name lookup, returns page_id */
52 aclGetDenyInfoPage(acl_deny_info_list
** head
, const char *name
, int redirect_allowed
)
54 acl_deny_info_list
*A
= NULL
;
56 debugs(28, 8, HERE
<< "got called for " << name
);
58 for (A
= *head
; A
; A
= A
->next
) {
59 acl_name_list
*L
= NULL
;
61 if (!redirect_allowed
&& strchr(A
->err_page_name
, ':') ) {
62 debugs(28, 8, HERE
<< "Skip '" << A
->err_page_name
<< "' 30x redirects not allowed as response here.");
66 for (L
= A
->acl_list
; L
; L
= L
->next
) {
67 if (!strcmp(name
, L
->name
)) {
68 debugs(28, 8, HERE
<< "match on " << name
);
69 return A
->err_page_id
;
75 debugs(28, 8, "aclGetDenyInfoPage: no match");
79 /* does name lookup, returns if it is a proxy_auth acl */
81 aclIsProxyAuth(const char *name
)
83 debugs(28, 5, "aclIsProxyAuth: called for " << name
);
90 if ((a
= ACL::FindByName(name
))) {
91 debugs(28, 5, "aclIsProxyAuth: returning " << a
->isProxyAuth());
92 return a
->isProxyAuth();
95 debugs(28, 3, "aclIsProxyAuth: WARNING, called for nonexistent ACL");
99 /* maex@space.net (05.09.96)
100 * get the info for redirecting "access denied" to info pages
102 * currently there is no optimization for
103 * - more than one deny_info line with the same url
104 * - a check, whether the given acl really is defined
105 * - a check, whether an acl is added more than once for the same url
109 aclParseDenyInfoLine(acl_deny_info_list
** head
)
112 acl_deny_info_list
*A
= NULL
;
113 acl_deny_info_list
*B
= NULL
;
114 acl_deny_info_list
**T
= NULL
;
115 acl_name_list
*L
= NULL
;
116 acl_name_list
**Tail
= NULL
;
118 /* first expect a page name */
120 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
121 debugs(28, DBG_CRITICAL
, "aclParseDenyInfoLine: " << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
122 debugs(28, DBG_CRITICAL
, "aclParseDenyInfoLine: missing 'error page' parameter.");
126 A
= (acl_deny_info_list
*)memAllocate(MEM_ACL_DENY_INFO_LIST
);
127 A
->err_page_id
= errorReservePageId(t
);
128 A
->err_page_name
= xstrdup(t
);
129 A
->next
= (acl_deny_info_list
*) NULL
;
130 /* next expect a list of ACL names */
133 while ((t
= strtok(NULL
, w_space
))) {
134 L
= (acl_name_list
*)memAllocate(MEM_ACL_NAME_LIST
);
135 xstrncpy(L
->name
, t
, ACL_NAME_SZ
);
140 if (A
->acl_list
== NULL
) {
141 debugs(28, DBG_CRITICAL
, "aclParseDenyInfoLine: " << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
142 debugs(28, DBG_CRITICAL
, "aclParseDenyInfoLine: deny_info line contains no ACL's, skipping");
143 memFree(A
, MEM_ACL_DENY_INFO_LIST
);
147 for (B
= *head
, T
= head
; B
; T
= &B
->next
, B
= B
->next
)
149 ; /* find the tail */
154 aclParseAccessLine(ConfigParser
&parser
, acl_access
** head
)
157 acl_access
*A
= NULL
;
158 acl_access
*B
= NULL
;
159 acl_access
**T
= NULL
;
161 /* first expect either 'allow' or 'deny' */
163 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
164 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: " << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
165 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: missing 'allow' or 'deny'.");
171 if (!strcmp(t
, "allow"))
172 A
->allow
= ACCESS_ALLOWED
;
173 else if (!strcmp(t
, "deny"))
174 A
->allow
= ACCESS_DENIED
;
176 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: " << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
177 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: expecting 'allow' or 'deny', got '" << t
<< "'.");
182 aclParseAclList(parser
, &A
->aclList
);
184 if (A
->aclList
== NULL
) {
185 debugs(28, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
186 debugs(28, DBG_CRITICAL
, "aclParseAccessLine: Access line contains no ACL's, skipping");
191 A
->cfgline
= xstrdup(config_input_line
);
192 /* Append to the end of this list */
194 for (B
= *head
, T
= head
; B
; T
= &B
->next
, B
= B
->next
);
197 /* We lock _acl_access structures in ACLChecklist::matchNonBlocking() */
201 aclParseAclList(ConfigParser
&parser
, ACLList
** head
)
203 ACLList
**Tail
= head
; /* sane name in the use below */
207 /* next expect a list of ACL names, possibly preceeded
208 * by '!' for negation */
210 while ((t
= strtok(NULL
, w_space
))) {
211 ACLList
*L
= new ACLList
;
218 debugs(28, 3, "aclParseAclList: looking for ACL name '" << t
<< "'");
219 a
= ACL::FindByName(t
);
222 debugs(28, DBG_CRITICAL
, "aclParseAclList: ACL name '" << t
<< "' not found.");
234 /*********************/
235 /* Destroy functions */
236 /*********************/
239 aclDestroyAcls(ACL
** head
)
243 debugs(28, 8, "aclDestroyACLs: invoked");
245 for (ACL
*a
= *head
; a
; a
= next
) {
254 aclDestroyAclList(ACLList
** head
)
257 debugs(28, 8, "aclDestroyAclList: invoked");
259 for (l
= *head
; l
; l
= *head
) {
266 aclDestroyAccessList(acl_access
** list
)
268 acl_access
*l
= NULL
;
269 acl_access
*next
= NULL
;
271 for (l
= *list
; l
; l
= next
) {
272 debugs(28, 3, "aclDestroyAccessList: '" << l
->cfgline
<< "'");
274 aclDestroyAclList(&l
->aclList
);
275 safe_free(l
->cfgline
);
282 /* maex@space.net (06.09.1996)
283 * destroy an acl_deny_info_list */
286 aclDestroyDenyInfoList(acl_deny_info_list
** list
)
288 acl_deny_info_list
*a
= NULL
;
289 acl_deny_info_list
*a_next
= NULL
;
290 acl_name_list
*l
= NULL
;
291 acl_name_list
*l_next
= NULL
;
293 debugs(28, 8, "aclDestroyDenyInfoList: invoked");
295 for (a
= *list
; a
; a
= a_next
) {
296 for (l
= a
->acl_list
; l
; l
= l_next
) {
302 xfree(a
->err_page_name
);
303 memFree(a
, MEM_ACL_DENY_INFO_LIST
);