Gadgets.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 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 "acl/Acl.h"
17 #include "acl/FilledChecklist.h"
18 #include "auth/AclProxyAuth.h"
19 #include "auth/basic/User.h"
20 #include "auth/Config.h"
21 #include "auth/CredentialsCache.h"
22 #include "auth/digest/User.h"
23 #include "auth/Gadgets.h"
24 #include "auth/negotiate/User.h"
25 #include "auth/ntlm/User.h"
26 #include "auth/Scheme.h"
27 #include "auth/User.h"
28 #include "auth/UserRequest.h"
29 #include "client_side.h"
30 #include "globals.h"
31 #include "http/Stream.h"
32 #include "HttpReply.h"
33 #include "HttpRequest.h"
34 
35 /**** PUBLIC FUNCTIONS (ALL GENERIC!) ****/
36 
37 int
39 {
40  int rv = 0;
41 
42  for (const auto *scheme : Auth::TheConfig.schemes) {
43  if (scheme->configured())
44  ++rv;
45  }
46 
47  debugs(29, 9, HERE << rv << " active.");
48 
49  return rv;
50 }
51 
52 int
54 {
55  int rv = Auth::Scheme::GetSchemes().size();
56 
57  debugs(29, 9, HERE << rv << " active.");
58 
59  return rv;
60 }
61 
62 static void
64 {
65  for (auto *scheme : *config)
66  scheme->registerWithCacheManager();
67 }
68 
69 void
71 {
72  /* If we do not have any auth config state to create stop now. */
73  if (!config)
74  return;
75 
76  for (auto *scheme : *config) {
77  if (scheme->configured())
78  scheme->init(scheme);
79  }
80 
82 }
83 
84 void
86 {
87  for (auto *scheme : Auth::TheConfig.schemes) {
88  if (scheme->configured())
89  scheme->rotateHelpers();
90  }
91 }
92 
93 void
95 {
96  debugs(29, 2, "Reset authentication State.");
97 
98  // username cache is cleared via Runner registry
99 
100  /* schedule shutdown of the helpers */
102 
103  /* free current global config details too. */
104  Auth::TheConfig.schemes.clear();
105 }
106 
107 std::vector<Auth::User::Pointer>
109 {
110  auto aucp_compare = [=](const Auth::User::Pointer lhs, const Auth::User::Pointer rhs) {
111  return lhs->userKey() < rhs->userKey();
112  };
113  std::vector<Auth::User::Pointer> v1, v2, rv, u1, u2;
114 #if HAVE_AUTH_MODULE_BASIC
115  if (Auth::SchemeConfig::Find("basic"))
116  u1 = Auth::Basic::User::Cache()->sortedUsersList();
117 #endif
118 #if HAVE_AUTH_MODULE_DIGEST
119  if (Auth::SchemeConfig::Find("digest"))
120  u2 = Auth::Digest::User::Cache()->sortedUsersList();
121 #endif
122  if (u1.size() > 0 || u2.size() > 0) {
123  v1.reserve(u1.size()+u2.size());
124  std::merge(u1.begin(), u1.end(),u2.begin(), u2.end(),
125  std::back_inserter(v1), aucp_compare);
126  u1.clear();
127  u2.clear();
128  }
129 #if HAVE_AUTH_MODULE_NEGOTIATE
130  if (Auth::SchemeConfig::Find("negotiate"))
131  u1 = Auth::Negotiate::User::Cache()->sortedUsersList();
132 #endif
133 #if HAVE_AUTH_MODULE_NTLM
134  if (Auth::SchemeConfig::Find("ntlm"))
135  u2 = Auth::Ntlm::User::Cache()->sortedUsersList();
136 #endif
137  if (u1.size() > 0 || u2.size() > 0) {
138  v2.reserve(u1.size()+u2.size());
139  std::merge(u1.begin(), u1.end(),u2.begin(), u2.end(),
140  std::back_inserter(v2), aucp_compare);
141  }
142  rv.reserve(v1.size()+v2.size());
143  std::merge(v1.begin(), v1.end(),v2.begin(), v2.end(),
144  std::back_inserter(rv), aucp_compare);
145  return rv;
146 }
147 
static std::vector< Scheme::Pointer > & GetSchemes()
Definition: Scheme.cc:44
Auth::ConfigVector schemes
set of auth_params directives
Definition: Config.h:32
struct _Cache Cache
std::vector< Auth::SchemeConfig * > ConfigVector
Definition: forward.h:23
void authenticateInit(Auth::ConfigVector *config)
Definition: Gadgets.cc:70
static void authenticateRegisterWithCacheManager(Auth::ConfigVector *config)
Definition: Gadgets.cc:63
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
void authenticateRotate(void)
Definition: Gadgets.cc:85
int authenticateSchemeCount(void)
Definition: Gadgets.cc:53
void authenticateReset(void)
Definition: Gadgets.cc:94
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
Auth::Config TheConfig
Definition: stub_libauth.cc:21
static SchemeConfig * Find(const char *proxy_auth)
Definition: SchemeConfig.cc:58
std::vector< Auth::User::Pointer > authenticateCachedUsersList()
Definition: Gadgets.cc:108
int authenticateActiveSchemeCount(void)
Definition: Gadgets.cc:38

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors