]>
git.ipfire.org Git - thirdparty/squid.git/blob - helpers/basic_auth/SASL/basic_sasl_auth.cc
ef0001ea428915d636aade87a733b49fa06ea60a
4 * SASL authenticator module for Squid.
5 * Copyright (C) 2002 Ian Castle <ian.castle@coldcomfortfarm.net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
21 * Install instructions:
23 * This program authenticates users against using cyrus-sasl
25 * Compile this program with: gcc -Wall -o sasl_auth sasl_auth.c -lsasl
26 * or with SASL2: gcc -Wall -o sasl_auth sasl_auth.c -lsasl2
30 #include "helpers/defines.h"
47 #include <sasl/sasl.h>
52 #define APP_NAME_SASL "basic_sasl_auth"
55 main(int argc
, char *argv
[])
57 char line
[HELPER_INPUT_BUFFER
];
58 char *username
, *password
;
59 #if SASL_VERSION_MAJOR < 2
64 sasl_conn_t
*conn
= NULL
;
66 /* make standard output line buffered */
67 setvbuf(stdout
, NULL
, _IOLBF
, 0);
69 rc
= sasl_server_init( NULL
, APP_NAME_SASL
);
71 if ( rc
!= SASL_OK
) {
72 fprintf(stderr
, "FATAL: %d %s\n", rc
, sasl_errstring(rc
, NULL
, NULL
));
76 #if SASL_VERSION_MAJOR < 2
77 rc
= sasl_server_new( APP_NAME_SASL
, NULL
, NULL
, NULL
, 0, &conn
);
79 rc
= sasl_server_new( APP_NAME_SASL
, NULL
, NULL
, NULL
, NULL
, NULL
, 0, &conn
);
82 if ( rc
!= SASL_OK
) {
83 fprintf(stderr
, "FATAL: %d %s\n", rc
, sasl_errstring(rc
, NULL
, NULL
));
87 while ( fgets( line
, HELPER_INPUT_BUFFER
, stdin
)) {
89 password
= strchr( line
, '\n' );
91 debug("ERROR: %s: Unexpected input '%s'\n", argv
[0], line
);
92 SEND_ERR("Unexpected Empty Input");
96 password
= strchr ( line
, ' ' );
98 debug("ERROR: %s: Unexpected input '%s' (no password)\n", argv
[0], line
);
99 SEND_ERR("No Password");
104 rfc1738_unescape(username
);
105 rfc1738_unescape(password
);
107 #if SASL_VERSION_MAJOR < 2
108 rc
= sasl_checkpass(conn
, username
, strlen(username
), password
, strlen(password
), &errstr
);
110 rc
= sasl_checkpass(conn
, username
, strlen(username
), password
, strlen(password
));
113 if ( rc
!= SASL_OK
) {
114 #if SASL_VERSION_MAJOR < 2
116 debug("errstr %s\n", errstr
);
118 if ( rc
!= SASL_BADAUTH
) {
119 debug("ERROR: %d %s\n", rc
, sasl_errstring(rc
, NULL
, NULL
));
120 SEND_ERR(sasl_errstring(rc
, NULL
, NULL
));