]> git.ipfire.org Git - thirdparty/squid.git/blame - src/auth/Config.cc
Move compat/unsafe.h protections from libcompat to source maintenance
[thirdparty/squid.git] / src / auth / Config.cc
CommitLineData
f5691f9c 1/*
f5691f9c 2 * DEBUG: section 29 Authenticator
3 * AUTHOR: Robert Collins
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.
26ac0430 21 *
f5691f9c 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.
26ac0430 26 *
f5691f9c 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
582c2af2 33#include "squid.h"
2d2b0bb7
AR
34#include "auth/Config.h"
35#include "auth/UserRequest.h"
d4806c91
CT
36#include "cache_cf.h"
37#include "ConfigParser.h"
582c2af2 38#include "Debug.h"
d4806c91 39#include "format/Format.h"
582c2af2 40#include "globals.h"
d4806c91 41#include "Store.h"
f5691f9c 42
9f3d2b2e 43Auth::ConfigVector Auth::TheConfig;
5817ee13
AJ
44
45/**
9f3d2b2e
AJ
46 * Get an User credentials object filled out for the given Proxy- or WWW-Authenticate header.
47 * Any decoding which needs to be done will be done.
48 *
49 * It may be a cached AuthUser or a new Unauthenticated object.
f5691f9c 50 * It may also be NULL reflecting that no user could be created.
51 */
c7baff40 52Auth::UserRequest::Pointer
d4806c91 53Auth::Config::CreateAuthUser(const char *proxy_auth, AccessLogEntry::Pointer &al)
f5691f9c 54{
55 assert(proxy_auth != NULL);
9f3d2b2e 56 debugs(29, 9, HERE << "header = '" << proxy_auth << "'");
f5691f9c 57
9f3d2b2e 58 Auth::Config *config = Find(proxy_auth);
f5691f9c 59
60 if (config == NULL || !config->active()) {
c6cf8dee 61 debugs(29, (shutting_down?3:DBG_IMPORTANT), (shutting_down?"":"WARNING: ") <<
8add28cd 62 "Unsupported or unconfigured/inactive proxy-auth scheme, '" << proxy_auth << "'");
f5691f9c 63 return NULL;
64 }
d4806c91
CT
65 static MemBuf rmb;
66 rmb.reset();
67 if (config->keyExtras) {
68 // %credentials and %username, which normally included in
69 // request_format, are - at this time, but that is OK
70 // because user name is added to key explicitly, and we do
71 // not want to store authenticated credentials at all.
72 config->keyExtras->assemble(rmb, al, 0);
73 }
f5691f9c 74
d4806c91 75 return config->decode(proxy_auth, rmb.hasContent() ? rmb.content() : NULL);
f5691f9c 76}
77
9f3d2b2e
AJ
78Auth::Config *
79Auth::Config::Find(const char *proxy_auth)
f5691f9c 80{
9f3d2b2e 81 for (Auth::ConfigVector::iterator i = Auth::TheConfig.begin(); i != Auth::TheConfig.end(); ++i)
f5691f9c 82 if (strncasecmp(proxy_auth, (*i)->type(), strlen((*i)->type())) == 0)
83 return *i;
84
85 return NULL;
86}
62ee09ca 87
9f3d2b2e 88/** Default behaviour is to expose nothing */
62ee09ca 89void
9f3d2b2e 90Auth::Config::registerWithCacheManager(void)
62ee09ca 91{}
d4806c91
CT
92
93void
94Auth::Config::parse(Auth::Config * scheme, int n_configured, char *param_str)
95{
96 if (strcmp(param_str, "key_extras") == 0) {
97 keyExtrasLine = ConfigParser::NextQuotedToken();
98 Format::Format *nlf = new ::Format::Format(scheme->type());
99 if (!nlf->parse(keyExtrasLine.termedBuf())) {
100 debugs(29, DBG_CRITICAL, "FATAL: Failed parsing key_extras formatting value");
101 self_destruct();
102 return;
103 }
104 if (keyExtras)
105 delete keyExtras;
106
107 keyExtras = nlf;
108
109 if (char *t = strtok(NULL, w_space)) {
110 debugs(29, DBG_CRITICAL, "FATAL: Unexpected argument '" << t << "' after request_format specification");
111 self_destruct();
112 }
113 } else {
114 debugs(29, DBG_CRITICAL, "Unrecognised " << scheme->type() << " auth scheme parameter '" << param_str << "'");
115 }
116}
117
118void
119Auth::Config::dump(StoreEntry *entry, const char *name, Auth::Config *scheme)
120{
121 if (keyExtrasLine.size() > 0)
122 storeAppendPrintf(entry, "%s %s key_extras \"%s\"\n", name, scheme->type(), keyExtrasLine.termedBuf());
123}
124
125void
126Auth::Config::done()
127{
128 delete keyExtras;
129 keyExtras = NULL;
130 keyExtrasLine.clean();
131}