]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/CertificateData.cc
Merged from trunk
[thirdparty/squid.git] / src / acl / CertificateData.cc
1 /*
2 * DEBUG: section 28 Access Control
3 * AUTHOR: Duane Wessels
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 *
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
33 */
34
35 #include "squid.h"
36 #include "acl/CertificateData.h"
37 #include "acl/Checklist.h"
38 #include "cache_cf.h"
39 #include "wordlist.h"
40
41 ACLCertificateData::ACLCertificateData(SSLGETATTRIBUTE *sslStrategy) : attribute (NULL), values (), sslAttributeCall (sslStrategy)
42 {}
43
44 ACLCertificateData::ACLCertificateData(ACLCertificateData const &old) : attribute (NULL), values (old.values), sslAttributeCall (old.sslAttributeCall)
45 {
46 if (old.attribute)
47 attribute = xstrdup (old.attribute);
48 }
49
50 template<class T>
51 inline void
52 xRefFree(T &thing)
53 {
54 xfree (thing);
55 }
56
57 ACLCertificateData::~ACLCertificateData()
58 {
59 safe_free (attribute);
60 }
61
62 template<class T>
63 inline int
64 splaystrcmp (T&l, T&r)
65 {
66 return strcmp ((char *)l,(char *)r);
67 }
68
69 bool
70 ACLCertificateData::match(SSL *ssl)
71 {
72 if (!ssl)
73 return 0;
74
75 char const *value = sslAttributeCall(ssl, attribute);
76
77 if (value == NULL)
78 return 0;
79
80 return values.match(value);
81 }
82
83 static void
84 aclDumpAttributeListWalkee(char * const & node_data, void *outlist)
85 {
86 /* outlist is really a wordlist ** */
87 wordlistAdd((wordlist **)outlist, node_data);
88 }
89
90 wordlist *
91 ACLCertificateData::dump()
92 {
93 wordlist *wl = NULL;
94 wordlistAdd(&wl, attribute);
95 /* damn this is VERY inefficient for long ACL lists... filling
96 * a wordlist this way costs Sum(1,N) iterations. For instance
97 * a 1000-elements list will be filled in 499500 iterations.
98 */
99 /* XXX FIXME: don't break abstraction */
100 values.values->walk(aclDumpAttributeListWalkee, &wl);
101 return wl;
102 }
103
104 void
105 ACLCertificateData::parse()
106 {
107 char *newAttribute = strtokFile();
108
109 if (!newAttribute)
110 self_destruct();
111
112 /* an acl must use consistent attributes in all config lines */
113 if (attribute) {
114 if (strcasecmp(newAttribute, attribute) != 0)
115 self_destruct();
116 } else
117 attribute = xstrdup(newAttribute);
118
119 values.parse();
120 }
121
122 bool
123 ACLCertificateData::empty() const
124 {
125 return values.empty();
126 }
127
128 ACLData<SSL *> *
129 ACLCertificateData::clone() const
130 {
131 /* Splay trees don't clone yet. */
132 return new ACLCertificateData(*this);
133 }