Squid Web Cache master
Loading...
Searching...
No Matches
Config.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 29 NTLM Authenticator */
10
11/* The functions in this file handle authentication.
12 * They DO NOT perform access control or auditing.
13 * See acl.c for access control and client_side.c for auditing */
14
15#include "squid.h"
16#include "auth/Gadgets.h"
17#include "auth/ntlm/Config.h"
18#include "auth/ntlm/Scheme.h"
19#include "auth/ntlm/User.h"
21#include "auth/State.h"
22#include "cache_cf.h"
23#include "client_side.h"
24#include "helper.h"
25#include "http/Stream.h"
26#include "HttpHeaderTools.h"
27#include "HttpReply.h"
28#include "HttpRequest.h"
29#include "mgr/Registration.h"
30#include "Store.h"
31#include "wordlist.h"
32
33/* NTLM Scheme */
35
37static int authntlm_initialised = 0;
38
39static hash_table *proxy_auth_cache = nullptr;
40
41void
42Auth::Ntlm::Config::rotateHelpers()
43{
44 /* schedule closure of existing helpers */
47 }
48
49 /* NP: dynamic helper restart will ensure they start up again as needed. */
50}
51
52/* free any allocated configuration details */
53void
54Auth::Ntlm::Config::done()
55{
57
59
62 }
63
64 if (!shutting_down)
65 return;
66
67 ntlmauthenticators = nullptr;
68
69 if (authenticateProgram)
70 wordlistDestroy(&authenticateProgram);
71
72 debugs(29, DBG_IMPORTANT, "Reconfigure: NTLM authentication configuration cleared.");
73}
74
75const char *
76Auth::Ntlm::Config::type() const
77{
78 return Auth::Ntlm::Scheme::GetInstance()->type();
79}
80
81/* Initialize helpers and the like for this auth scheme. Called AFTER parsing the
82 * config file */
83void
84Auth::Ntlm::Config::init(Auth::SchemeConfig *)
85{
86 if (authenticateProgram) {
87
89
90 if (ntlmauthenticators == nullptr)
91 ntlmauthenticators = statefulhelper::Make("ntlmauthenticator");
92
95
97
98 ntlmauthenticators->cmdline = authenticateProgram;
99
100 ntlmauthenticators->childs.updateLimits(authenticateChildren);
101
103
105 }
106}
107
108void
109Auth::Ntlm::Config::registerWithCacheManager(void)
110{
111 Mgr::RegisterAction("ntlmauthenticator",
112 "NTLM User Authenticator Stats",
114}
115
116bool
117Auth::Ntlm::Config::active() const
118{
119 return authntlm_initialised == 1;
120}
121
122/* NTLM Scheme */
123
124void
125Auth::Ntlm::Config::fixHeader(Auth::UserRequest::Pointer auth_user_request, HttpReply *rep, Http::HdrType hdrType, HttpRequest * request)
126{
127 if (!authenticateProgram)
128 return;
129
130 /* Need keep-alive */
131 if (!request->flags.proxyKeepalive && request->flags.mustKeepalive)
132 return;
133
134 /* New request, no user details */
135 if (auth_user_request == nullptr) {
136 debugs(29, 9, "Sending type:" << hdrType << " header: 'NTLM'");
137 httpHeaderPutStrf(&rep->header, hdrType, "NTLM");
138
139 if (!keep_alive) {
140 /* drop the connection */
141 request->flags.proxyKeepalive = false;
142 }
143 } else {
144 Auth::Ntlm::UserRequest *ntlm_request = dynamic_cast<Auth::Ntlm::UserRequest *>(auth_user_request.getRaw());
145 assert(ntlm_request != nullptr);
146
147 switch (ntlm_request->user()->credentials()) {
148
149 case Auth::Failed:
150 /* here it makes sense to drop the connection, as auth is
151 * tied to it, even if MAYBE the client could handle it - Kinkie */
152 request->flags.proxyKeepalive = false;
153 [[fallthrough]];
154
155 case Auth::Ok:
156 /* Special case: authentication finished OK but disallowed by ACL.
157 * Need to start over to give the client another chance.
158 */
159 [[fallthrough]];
160
161 case Auth::Unchecked:
162 /* semantic change: do not drop the connection.
163 * 2.5 implementation used to keep it open - Kinkie */
164 debugs(29, 9, "Sending type:" << hdrType << " header: 'NTLM'");
165 httpHeaderPutStrf(&rep->header, hdrType, "NTLM");
166 break;
167
168 case Auth::Handshake:
169 /* we're waiting for a response from the client. Pass it the blob */
170 debugs(29, 9, "Sending type:" << hdrType << " header: 'NTLM " << ntlm_request->server_blob << "'");
171 httpHeaderPutStrf(&rep->header, hdrType, "NTLM %s", ntlm_request->server_blob);
172 safe_free(ntlm_request->server_blob);
173 break;
174
175 default:
176 debugs(29, DBG_CRITICAL, "NTLM Auth fixHeader: state " << ntlm_request->user()->credentials() << ".");
177 fatal("unexpected state in AuthenticateNTLMFixErrorHeader.\n");
178 }
179 }
180}
181
182static void
184{
186 ntlmauthenticators->packStatsInto(sentry, "NTLM Authenticator Statistics");
187}
188
189/*
190 * Decode a NTLM [Proxy-]Auth string, placing the results in the passed
191 * Auth_user structure.
192 */
194Auth::Ntlm::Config::decode(char const *proxy_auth, const HttpRequest *, const char *aRequestRealm)
195{
196 Auth::Ntlm::User *newUser = new Auth::Ntlm::User(Auth::SchemeConfig::Find("ntlm"), aRequestRealm);
197 Auth::UserRequest::Pointer auth_user_request = new Auth::Ntlm::UserRequest();
198 assert(auth_user_request->user() == nullptr);
199
200 auth_user_request->user(newUser);
201 auth_user_request->user()->auth_type = Auth::AUTH_NTLM;
202
203 auth_user_request->user()->BuildUserKey(proxy_auth, aRequestRealm);
204
205 /* all we have to do is identify that it's NTLM - the helper does the rest */
206 debugs(29, 9, "decode: NTLM authentication");
207 return auth_user_request;
208}
209
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...)
#define assert(EX)
Definition assert.h:17
void AUTHSSTATS(StoreEntry *)
Definition Gadgets.h:21
static hash_table * proxy_auth_cache
Definition Config.cc:39
static AUTHSSTATS authenticateNTLMStats
Definition Config.cc:34
Helper::StatefulClientPointer ntlmauthenticators
Definition Config.cc:36
static int authntlm_initialised
Definition Config.cc:37
virtual void done()
static SchemeConfig * Find(const char *proxy_auth)
virtual User::Pointer user()
ChildConfig & updateLimits(const ChildConfig &rhs)
void packStatsInto(Packable *p, const char *label=nullptr) const
Dump some stats about the helper state to a Packable object.
Definition helper.cc:695
ChildConfig childs
Configuration settings for number running.
Definition helper.h:119
wordlist * cmdline
Definition helper.h:115
RequestFlags flags
HttpHeader header
Definition Message.h:74
C * getRaw() const
Definition RefCount.h:89
bool proxyKeepalive
static Pointer Make(const char *name)
Definition helper.cc:764
void openSessions() override
Definition helper.cc:328
#define DBG_IMPORTANT
Definition Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define DBG_CRITICAL
Definition Stream.h:37
#define IPC_STREAM
Definition defines.h:104
void fatal(const char *message)
Definition fatal.cc:28
int shutting_down
HASHHASH hash_string
Definition hash.h:45
hash_table * hash_create(HASHCMP *, int, HASHHASH *)
Definition hash.cc:108
int HASHCMP(const void *, const void *)
Definition hash.h:13
void helperStatefulShutdown(const statefulhelper::Pointer &hlp)
Definition helper.cc:809
@ AUTH_NTLM
Definition Type.h:20
void RegisterAction(char const *action, char const *desc, OBJH *handler, Protected, Atomic, Format)
void wordlistDestroy(wordlist **list)
destroy a wordlist
Definition wordlist.cc:16
#define safe_free(x)
Definition xalloc.h:73