Squid Web Cache
v8/master
Loading...
Searching...
No Matches
basic_sasl_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
* SASL authenticator module for Squid.
11
* Copyright (C) 2002 Ian Castle <ian.castle@coldcomfortfarm.net>
12
*
13
* This program is free software; you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation; either version 2 of the License, or
16
* (at your option) any later version.
17
*
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License along
24
* with this program; if not, see <https://www.gnu.org/licenses/>.
25
*
26
* Install instructions:
27
*
28
* This program authenticates users against using cyrus-sasl
29
*
30
* Compile this program with: gcc -Wall -o sasl_auth sasl_auth.c -lsasl
31
* or with SASL2: gcc -Wall -o sasl_auth sasl_auth.c -lsasl2
32
*
33
*/
34
#include "
squid.h
"
35
#include "
helper/protocol_defines.h
"
36
#include "
rfc1738.h
"
37
#include "
util.h
"
38
39
#include <cerrno>
40
#include <cstdlib>
41
#include <cstring>
42
#if HAVE_SASL_SASL_H
43
#include <sasl/sasl.h>
44
#else
45
#include <sasl.h>
46
#endif
47
48
#define APP_NAME_SASL "basic_sasl_auth"
49
50
int
51
main
(
int
,
char
*argv[])
52
{
53
char
line[
HELPER_INPUT_BUFFER
];
54
char
*username, *password;
55
#if SASL_VERSION_MAJOR < 2
56
const
char
*errstr;
57
#endif
58
59
int
rc;
60
sasl_conn_t *conn =
nullptr
;
61
62
/* make standard output line buffered */
63
setvbuf(stdout,
nullptr
, _IOLBF, 0);
64
65
rc = sasl_server_init(
nullptr
,
APP_NAME_SASL
);
66
67
if
( rc != SASL_OK ) {
68
fprintf(stderr,
"FATAL: %d %s\n"
, rc, sasl_errstring(rc,
nullptr
,
nullptr
));
69
exit(EXIT_FAILURE);
70
}
71
72
#if SASL_VERSION_MAJOR < 2
73
rc = sasl_server_new(
APP_NAME_SASL
,
nullptr
,
nullptr
,
nullptr
, 0, &conn );
74
#else
75
rc = sasl_server_new(
APP_NAME_SASL
,
nullptr
,
nullptr
,
nullptr
,
nullptr
,
nullptr
, 0, &conn );
76
#endif
77
78
if
( rc != SASL_OK ) {
79
fprintf(stderr,
"FATAL: %d %s\n"
, rc, sasl_errstring(rc,
nullptr
,
nullptr
));
80
exit(EXIT_FAILURE);
81
}
82
83
while
( fgets( line,
HELPER_INPUT_BUFFER
, stdin )) {
84
username = &line[0];
85
password = strchr( line,
'\n'
);
86
if
(!password) {
87
debug
(
"ERROR: %s: Unexpected input '%s'\n"
, argv[0], line);
88
SEND_ERR
(
"Unexpected Empty Input"
);
89
continue
;
90
}
91
*password =
'\0'
;
92
password = strchr ( line,
' '
);
93
if
(!password) {
94
debug
(
"ERROR: %s: Unexpected input '%s' (no password)\n"
, argv[0], line );
95
SEND_ERR
(
"No Password"
);
96
continue
;
97
}
98
*password =
'\0'
;
99
++password;
100
101
rfc1738_unescape
(username);
102
rfc1738_unescape
(password);
103
104
#if SASL_VERSION_MAJOR < 2
105
rc = sasl_checkpass(conn, username, strlen(username), password, strlen(password), &errstr);
106
#else
107
rc = sasl_checkpass(conn, username, strlen(username), password, strlen(password));
108
#endif
109
110
if
( rc != SASL_OK ) {
111
#if SASL_VERSION_MAJOR < 2
112
if
( errstr ) {
113
debug
(
"errstr %s\n"
, errstr);
114
}
115
if
( rc != SASL_BADAUTH ) {
116
debug
(
"ERROR: %d %s\n"
, rc, sasl_errstring(rc,
nullptr
,
nullptr
));
117
SEND_ERR
(sasl_errstring(rc,
nullptr
,
nullptr
));
118
}
else
119
#endif
120
SEND_ERR
(
""
);
121
}
else
{
122
SEND_OK
(
""
);
123
}
124
}
125
126
sasl_dispose(&conn);
127
sasl_done();
128
return
EXIT_SUCCESS;
129
}
130
HELPER_INPUT_BUFFER
#define HELPER_INPUT_BUFFER
Definition
UserRequest.cc:24
APP_NAME_SASL
#define APP_NAME_SASL
Definition
basic_sasl_auth.cc:48
debug
void debug(const char *format,...)
Definition
debug.cc:19
main
int main()
Definition
kerberos_ldap_group.cc:491
protocol_defines.h
SEND_ERR
#define SEND_ERR(x)
Definition
protocol_defines.h:54
SEND_OK
#define SEND_OK(x)
Definition
protocol_defines.h:51
rfc1738.h
rfc1738_unescape
void rfc1738_unescape(char *url)
Definition
rfc1738.cc:146
squid.h
util.h
squid
src
auth
basic
SASL
basic_sasl_auth.cc
Generated by
1.9.8