Squid Web Cache v8/master
Loading...
Searching...
No Matches
basic_sspi_auth.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2026 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/*
10 NT_auth - Version 2.0
11
12 Returns OK for a successful authentication, or ERR upon error.
13
14 Guido Serassio, Torino - Italy
15
16 Uses code from -
17 Antonino Iannella 2000
18 Andrew Tridgell 1997
19 Richard Sharpe 1996
20 Bill Welliver 1999
21
22 * Distributed freely under the terms of the GNU General Public License,
23 * version 2 or later. See the file COPYING for licensing details
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, see <https://www.gnu.org/licenses/>.
32 */
33
34#include "squid.h"
37#include "rfc1738.h"
38#include "util.h"
39
40#if GETOPT_H
41#include <getopt.h>
42#endif
43
44static char NTGroup[256];
50
51/*
52 * options:
53 * -A can specify a Windows Local Group name allowed to authenticate.
54 * -D can specify a Windows Local Group name not allowed to authenticate.
55 * -O can specify the default Domain against to authenticate.
56 */
57static void
58usage(const char *name)
59{
60 fprintf(stderr, "Usage:\n%s [-A|D UserGroup][-O DefaultDomain][-d]\n"
61 "-A can specify a Windows Local Group name allowed to authenticate\n"
62 "-D can specify a Windows Local Group name not allowed to authenticate\n"
63 "-O can specify the default Domain against to authenticate\n"
64 "-d enable debugging.\n"
65 "-h this message\n\n",
66 name);
67}
68
69static void
70process_options(int argc, char *argv[])
71{
72 int opt;
73 while (-1 != (opt = getopt(argc, argv, "dhA:D:O:"))) {
74 switch (opt) {
75 case 'A':
79 break;
80 case 'D':
84 break;
85 case 'O':
86 strncpy(Default_NTDomain, optarg, DNLEN);
87 break;
88 case 'd':
89 debug_enabled = 1;
90 break;
91 case 'h':
92 usage(argv[0]);
93 exit(EXIT_SUCCESS);
94 case '?':
95 opt = optopt;
96 [[fallthrough]];
97 default:
98 fprintf(stderr, "FATAL: Unknown option: -%c\n", opt);
99 usage(argv[0]);
100 exit(EXIT_FAILURE);
101 }
102 }
103}
104
105/* Main program for simple authentication.
106 Scans and checks for Squid input, and attempts to validate the user.
107*/
108int
109main(int argc, char **argv)
110{
111 char wstr[HELPER_INPUT_BUFFER];
112 char username[256];
113 char password[256];
114 char *p;
115 int err = 0;
116
117 process_options(argc, argv);
118
120 fprintf(stderr, "FATAL: can't initialize SSPI, exiting.\n");
121 exit(EXIT_FAILURE);
122 }
123 debug("SSPI initialized OK\n");
124
125 atexit(UnloadSecurityDll);
126
127 /* initialize FDescs */
128 setbuf(stdout, nullptr);
129 setbuf(stderr, nullptr);
130
131 while (fgets(wstr, HELPER_INPUT_BUFFER, stdin) != NULL) {
132
133 if (NULL == strchr(wstr, '\n')) {
134 err = 1;
135 continue;
136 }
137 if (err) {
138 SEND_ERR("Oversized message");
139 err = 0;
140 fflush(stdout);
141 continue;
142 }
143
144 if ((p = strchr(wstr, '\n')) != NULL)
145 *p = '\0'; /* strip \n */
146 if ((p = strchr(wstr, '\r')) != NULL)
147 *p = '\0'; /* strip \r */
148 /* Clear any current settings */
149 username[0] = '\0';
150 password[0] = '\0';
151 sscanf(wstr, "%s %s", username, password); /* Extract parameters */
152
153 debug("Got %s from Squid\n", wstr);
154
155 /* Check for invalid or blank entries */
156 if ((username[0] == '\0') || (password[0] == '\0')) {
157 SEND_ERR("Invalid Request");
158 fflush(stdout);
159 continue;
160 }
161 rfc1738_unescape(username);
162 rfc1738_unescape(password);
163
164 debug("Trying to validate; %s %s\n", username, password);
165
166 if (Valid_User(username, password, NTGroup) == NTV_NO_ERROR)
167 SEND_OK("");
168 else
170 err = 0;
171 fflush(stdout);
172 }
173 return EXIT_SUCCESS;
174}
175
#define HELPER_INPUT_BUFFER
int debug_enabled
char * NTAllowedGroup
static char NTGroup[256]
static void process_options(int argc, char *argv[])
int UseAllowedGroup
char * NTDisAllowedGroup
int UseDisallowedGroup
void debug(const char *format,...)
Definition debug.cc:19
static void usage(void)
int optopt
Definition getopt.c:49
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition getopt.c:62
char * optarg
Definition getopt.c:51
int main()
#define xstrdup
#define SEND_ERR(x)
#define SEND_OK(x)
void rfc1738_unescape(char *url)
Definition rfc1738.cc:146
void UnloadSecurityDll(void)
Definition sspwin32.cc:77
HMODULE LoadSecurityDll(int mode, const char *SSP_Package)
Definition sspwin32.cc:104
#define NTLM_PACKAGE_NAME
Definition sspwin32.h:18
#define SSP_BASIC
Definition sspwin32.h:42
#define NULL
Definition types.h:145
int Valid_User(char *UserName, char *Password, char *)
Definition valid.cc:119
const char * errormsg
Definition valid.cc:43
char Default_NTDomain[DNLEN+1]
Definition valid.cc:42
#define NTV_NO_ERROR
Definition valid.h:47
#define safe_free(x)
Definition xalloc.h:73