]>
git.ipfire.org Git - thirdparty/squid.git/blob - helpers/basic_auth/SASL/sasl_auth.c
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
36 #ifdef HAVE_SASL_SASL_H
37 #include <sasl/sasl.h>
42 #define APP_NAME_SASL "squid_sasl_auth"
45 main(int argc
, char *argv
[])
48 char *username
, *password
;
49 #if SASL_VERSION_MAJOR < 2
54 sasl_conn_t
*conn
= NULL
;
56 /* make standard output line buffered */
57 setvbuf(stdout
, NULL
, _IOLBF
, 0);
59 rc
= sasl_server_init( NULL
, APP_NAME_SASL
);
61 if ( rc
!= SASL_OK
) {
62 fprintf( stderr
, "error %d %s\n", rc
, sasl_errstring(rc
, NULL
, NULL
));
63 fprintf( stdout
, "ERR\n" );
67 #if SASL_VERSION_MAJOR < 2
68 rc
= sasl_server_new( APP_NAME_SASL
, NULL
, NULL
, NULL
, 0, &conn
);
70 rc
= sasl_server_new( APP_NAME_SASL
, NULL
, NULL
, NULL
, NULL
, NULL
, 0, &conn
);
73 if ( rc
!= SASL_OK
) {
74 fprintf( stderr
, "error %d %s\n", rc
, sasl_errstring(rc
, NULL
, NULL
));
75 fprintf( stdout
, "ERR\n" );
79 while ( fgets( line
, sizeof( line
), stdin
)) {
81 password
= strchr( line
, '\n' );
83 fprintf( stderr
, "authenticator: Unexpected input '%s'\n", line
);
84 fprintf( stdout
, "ERR\n" );
88 password
= strchr ( line
, ' ' );
90 fprintf( stderr
, "authenticator: Unexpected input '%s'\n", line
);
91 fprintf( stdout
, "ERR\n" );
96 rfc1738_unescape(username
);
97 rfc1738_unescape(password
);
99 #if SASL_VERSION_MAJOR < 2
100 rc
= sasl_checkpass(conn
, username
, strlen(username
), password
, strlen(password
), &errstr
);
102 rc
= sasl_checkpass(conn
, username
, strlen(username
), password
, strlen(password
));
105 if ( rc
!= SASL_OK
) {
106 #if SASL_VERSION_MAJOR < 2
108 fprintf( stderr
, "errstr %s\n", errstr
);
110 if ( rc
!= SASL_BADAUTH
) {
111 fprintf( stderr
, "error %d %s\n", rc
, sasl_errstring(rc
, NULL
, NULL
));
114 fprintf( stdout
, "ERR\n" );
116 fprintf( stdout
, "OK\n" );
121 sasl_dispose( &conn
);